网址的参数未在传递数组中传递(路由cakephp 2.x)

时间:2018-07-12 12:06:03

标签: cakephp routing routes cakephp-2.3

当我的网址带有参数时,路由不起作用。

我的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()
)

请帮助我 请原谅我平庸的英语 谢谢

0 个答案:

没有答案