开发者

cakePHP 1.3 routes and named params

I had this kind of routes that used to work on cakePHP 1.2

Router::connect('/mycategory/my-region', array('controller'=>'search', 'ac开发者_StackOverflow中文版tion'=>'properties''named'=>array('region'=>01)));

How can I accomplish the same in cake 1.3

thanks


If my-region always equals to 01, then your solution is as good as any other I guess. If however you'd like to be able to have several different regions, then I would suggest something like the following route:

Router::connect('/mycategory/:my_region', 
    array('controller' => 'search', 'action' => 'properties'),
    array('pass' => array('my_region'), 'my_region' => '[\#a-zA-Z0-9_-]+')
);

And so you can get the value of my-regionin your controller like so:

function properties($my_region = NULL) {
    $regions = array('my-region' => '01');
    $id = $regions[$my_region];
}

The controller part can be greatly improved, with if/switch statements. Just wanted to give a very basic example.

Edit: And then, build your links like so:

<?php echo $this->ExHtml->link(
    'My Region',
    array('controller' => 'search', 'action' => 'properties', 'my_region' => 'my-region')
); ?>

which should automagically output: <a href="/mycategory/my-region">My Region</a>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜