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

How can I write working router::connect to send such links to

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

Please take note, that in the url it is "c" but I need to forward it as "cat".

Thanks in advance!

有帮助吗?

解决方案

You can specify the routing as follow in the Config/routes.php.

```

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

```

and specify the link as

```

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

```

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top