Cakephp router :: connect to forward named params

时间:2013-10-10 11:58:00

标签: cakephp connect router cakephp-2.3 forwarding

http://domain.com/foo/c:1

如何编写工作路由器:: connect以将此类链接发送到

controller=listings
action=search
named array(cat=1) the id I do not know, it's a dynamic url

请注意,在网址中它是“c”但我需要将其转发为“cat”。

提前致谢!

1 个答案:

答案 0 :(得分:1)

您可以在Config / routes.php。

中指定路由

```

Router::connect(
        '/:query/*', array('controller' => 'listings', 'action' => 'search'), array(
            'params' => array('query', 'cat'),
            'named' => array(
                'query', 'cat'
            )
        )
    );

```

并将链接指定为

```

echo $this->Html->link('text goes here', array('controller' => 'listings', 'action' => 'search', 'query' => 'foo', 'cat' => 1));

```