当我的网址带有参数时,路由不起作用。
我的routes.php代码:
Router::connect('/contenu/:title',array('controller' => 'contennts', 'action' => 'view'),array('pass' => array('id','title'),'id' => "[0-9]+",'title' => "[a-zA-Z0-9\-]+"));
我在url中发送参数的视图代码:
<a href='<?php echo $this->Html->url(array('action' => 'view','id' => $contennt['Contennt']['id'],'title' => $contennt['Contennt']['rubrique']));?>'>Voir</a>
我的控制器代码:
public function view($id = null,$title=null) {
if($this->Session->read('Auth.User')){
$this->layout="admin";
}else {
$this->layout="default";}
if (!$this->Contennt->exists($id)) {
throw new NotFoundException(__('Invalid contennt'));
}
$options = array('conditions' => array('Contennt.' . $this->Contennt->primaryKey => $id));
$this->set('contennt', $this->Contennt->find('first', $options));
}
当我调试($ this-> request)时,我得到以下结果:
params => array(
'plugin' => null,
'controller' => 'contennts',
'action' => 'view',
'named' => array(
'id' => '5',
'title' => 'Aperçu historique'
),
'pass' => array()
)
请帮助我 请原谅我平庸的英语 谢谢