本文介绍了带参数的CakePHP 2.x自定义路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的CakePHP应用程序中,我想在自定义路由中传递参数.
In my CakePHP App I'd like to pass arguments in a custom route.
现在有效
domain.com/dealers/view/1
domain.com/dealers/view/1
我想做什么
domain.com/washington/dealers/view/1
domain.com/washington/dealers/view/1
这是我在route.php中的代码:
Router::connect('/:city/dealers/view/:id', array('controller' => 'dealers', 'action' => 'view'),
array(
'pass' => array('city', 'id')
),
array('city' => '[a-z]+')
);
这只是将 domain.com/washington/dealers/view/1 重定向到 domain.com/dealers/index ,原因很明显是我没有正确通过参数.有人知道我在想什么吗?
This just redirects domain.com/washington/dealers/view/1 to domain.com/dealers/index for the obvious reason that I did not properly pass the parameters. Does anyone know what I am missing?
推荐答案
城市不应位于单独的数组中,例如:
city should not be in a separate array ex:
Router::connect(
'/:city/dealers/view/:id',
array('controller' => 'dealers', 'action' => 'index'),
array(
'pass' => array('city', 'id'),
'city' => '[a-z]+'
));
这篇关于带参数的CakePHP 2.x自定义路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!