tags:

views:

33

answers:

1

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?

+2  A: 

Quite undocumented, but mentioned, this solved it:

Router::connectNamed(array('namedParameter', 'page', 'sort', 'direction'));
sibidiba