Yii : Facebook 风格的 url 路线 [英] Yii : Facebook style url route
本文介绍了Yii : Facebook 风格的 url 路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置我的 Yii webapp,以便 url
I would like to set up my Yii webapp so that the url
/username 将显示该用户的用户记录.
/username will show the user record for that user.
我试过了
'<username>'=> 'user/view'
,但这会导致错误 400.
, but this results in an error 400.
'<id:\d+>'=> 'user/view'
有效.
推荐答案
我已经设法弄清楚我做错了什么.
I've managed to work out what I was doing wrong.
您在 url 路由中放置的变量需要与控制器操作中的功能相对应.
The variables that you put in your url routes need to correspond to the functions in your controller actions.
所以我把gii生成的标准actionView改成
So I changed the standard actionView generated by gii to
public function actionView($username) {
$model=User::model()->find("username = '".$username."'");
$this->render('view',array('model'=>$model);
}
现在...<代码>'<用户名>'=>'user/view' 作为 url 路由按预期工作.
Now . . . '<username>'=> 'user/view'
as a url route works as expected .
这篇关于Yii : Facebook 风格的 url 路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文