probleme simple : route cake php
Bonjour,
je planche sur un gros probleme de routing depuis 12h,
malgrès des codes identiques pour mes routes, controller, vues et modeles, cake me génère deux liens différents :
http://localhost/cakebase/page/article-2-31
http://localhost/cakebase/truc/show/id:30/slug:page-1
Pourquoi?
Merci!
j'ai deux routes :
Code:
1 2 3 4 5 6 7 8
| Router::connect('/truc/:slug-:id',
array('controller'=>'trucs','action'=>'show'),
array('pass'=> array('id','slug'))
);
Router::connect('/page/:slug-:id',
array('controller'=>'page','action'=>'show'),
array('pass'=> array('id','slug'))
); |
TrucsController.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<?php
class TrucsController extends AppController{
function index () {
$d['truc']= $this->Truc->find('all') ;
$this->set($d);
}
} |
PagesController.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <?php
class PagesController extends AppController{
function index () {
$d['page']= $this->Page->find('all') ;
$this->set($d);
}
} |
model page.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php
class Page extends AppModel{
public function afterFind($data,$primary = false){
foreach($data as $k=>$d){
if(isset($d['Page']['slug']) && isset($d['Page']['id']) ){
$d['Page']['link'] = array(
'controller' => 'page', //met au pluriel post ou page
'action' => 'show',
'id' => $d['Page']['id'],
'slug' => $d['Page']['slug']
);
}
$data[$k] = $d;
debug($d);
}
return $data;
}
}
} |
Truc.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php
class Truc extends AppModel{
public function afterFind($data,$primary = false){
foreach($data as $k=>$d){
if(isset($d['Truc']['slug']) && isset($d['Truc']['id']) ){
$d['Truc']['link'] = array(
'controller' => 'truc', //met au pluriel post ou page
'action' => 'show',
'id' => $d['Truc']['id'],
'slug' => $d['Truc']['slug']
);
}
$data[$k] = $d;
debug($d);
}
return $data;
}
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| view/Pages/index.php
<?php
echo "</BR>debut index.ctp";
foreach($page as $k=>$v) :
$v = current($v);
debug($v['link']);
echo $this->Html->link($v['name'],$v['link']);?>
<?php endforeach;
echo "fin index.ctp.</BR>";?>
et /Trucs/index.php qui sont identiques |
Code:
1 2 3 4 5 6 7 8 9
|
<?php
echo "</BR>debut index.ctp";
foreach($truc as $k=>$v) :
$v = current($v);
debug($v['link']);
echo $this->Html->link($v['name'],$v['link']);?>
<?php endforeach;
echo "fin index.ctp.</BR>";?> |