Trouble with Router::url() when using named parameters

Posted by sibidiba on Stack Overflow See other posts from Stack Overflow or by sibidiba
Published on 2010-05-11T09:57:19Z Indexed on 2010/05/11 10:04 UTC
Read the original article Hit count: 288

Filed under:
|

I'm generating plain simple links with CakePHP's HtmlHelper the following way:

$html->link("Newest", array(
            'controller' => 'posts',
            'action' => 'listView',
            'page'=> 1,
            'sort'=>'Question.created',
            'direction'=>'desc',
    ));

Having the following route rule:

Router::connect('/foobar/*',array(
        'controller' => 'posts',
        'action' => 'listView'
));

The link is nicely generated as /foobar/page:1/sort:Question.created/direction:desc. Just as I want, it uses my URL prefix instead of controller/action names.

However, for some links I must add named parameters like this:

$html->link("Newest", array(
            'controller' => 'posts',
            'action' => 'listView',
            'page'=> 1,
            'sort'=>'Question.created',
            'direction'=>'desc',
            'namedParameter' => 'namedParameterValue'
    ));

The link in this case points to /posts/listView/page:1/sort:Question.created/direction:desc/namedParameter:namedParameterValue. But I do not want to have contoller/action names in my URL-s, why is Cake ignoring in this case my routers configuration?

© Stack Overflow or respective owner

Related posts about cakephp

Related posts about php