router::connect 在 CakePHP 中转发命名参数

问题描述 投票:0回答:1

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

我如何编写工作 router::connect 来发送此类链接

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

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

cakephp cakephp-2.3 cakephp-routing
1个回答
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));

```

© www.soinside.com 2019 - 2024. All rights reserved.