Yii url路由

Yii url路由,yii,routing,Yii,Routing,我有一个url example.com/information/london。当有人调用这个url时,我想调用控制器信息及其索引方法。但我想在伦敦将slug作为jobs传递,即example.com/information/jobs-in-london如何通过在config/main.php中编写url规则来实现这一点。 i、 e我想将我的页面example.com/information/london重定向到example.com/information/jobs-in-london,但不想使

我有一个url example.com/information/london。当有人调用这个url时,我想调用控制器信息及其索引方法。但我想在伦敦将slug作为jobs传递,即example.com/information/jobs-in-london如何通过在config/main.php中编写url规则来实现这一点。 i、 e我想将我的页面example.com/information/london重定向到example.com/information/jobs-in-london,但不想使用.htaccess我只想通过url路由规则来实现这一点我已经通过编写

'<_c:(information)>/<slug:london>'=>'information/index/jobs-in-london' 

你的问题不清楚。您可能是指以下任一情况:

网址:

规则:

段塞结果:

jobs-in-london
jobs-in-singapore
jobs-in-london
jobs-in-singapore
网址:

规则:

段塞结果:

jobs-in-london
jobs-in-singapore
jobs-in-london
jobs-in-singapore

以下是您在路线中必须执行的操作:

'<controller:(information)>/<slug:>' => '<controller>/index'

为了检查slug是什么,您对函数所做的操作是正确的。

感谢samuel的回答。。。。实际上,如果我点击了这个url示例/information/lodon,我只想发送一个请求。我希望slug应该作为伦敦的作业传递。换句话说,我想在我的配置信息/london=>information/index/jobs in london中添加这个规则。希望你明白我想说的
example.com/information/jobs-in-london
example.com/information/jobs-in-singapore
'information/<slug:jobs-in-.+>' => 'information/index',
public function actionIndex($slug)
{
    var_dump($slug);
}
jobs-in-london
jobs-in-singapore
'<controller:(information)>/<slug:>' => '<controller>/index'
Yii::app()->createUrl('information/index', array('slug' => 'jobs-in-london'));