learnplus
learnplus

Reputation: 269

cakephp 2.6 passed params in Router not working

Here is my code :

Router::connect('/edit_topic/:id', array('controller' => 'topics', 'action' => 'edit'),array('pass' => array('id'),'id' => '[0-9]+'));

The result with:

debug($this->request);
die();  

is like that:

object(CakeRequest) {
params => array(
    'plugin' => null,
    'controller' => 'topics',
    'action' => 'edit',
    'named' => array(),
    'pass' => array(
        (int) 0 => '14'
    ),
    'id' => '14'
)

As you cant see we found id in two places,inside pass array, and also inside params array, tha's my problem. I want to fix that,so that id appears only inside pass array

Upvotes: 1

Views: 86

Answers (1)

ADmad
ADmad

Reputation: 8100

This is this expected behavior you can't change it. Any route element used (:id in your case) will be available under CakeRequest::$params property and since you have set it to "passed" it's also available under params['pass'].

Only option you have is to unset params['id'] yourself in say controller's beforeFilter() callback. Though I don't really see why having it is a problem.

Upvotes: 3

Related Questions