Yii URL 管理 [英] Yii URL Management

查看:31
本文介绍了Yii URL 管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要特定 url 用法的用例.我希望用户拥有自己的页面,并且 url 应该让他们很容易记住他们的页面.

I have a usecase which requires a specific usage of urls. I want the users to have their own page and the url should be in such a way it is easy for them to remember their page.

我正在考虑将 url 设为 DOMAIN.COM/USERNAME

I was thinking of making the url DOMAIN.COM/USERNAME

我怎样才能做到这一点?我可能应该制作一个网址管理器?我怎样才能以这种方式使正常"控制器仍然可以工作?

How can I achieve this? I probably should make an url manager? How can I make it in such way the 'normal' controllers would still work?

推荐答案

好吧,你应该阅读这个:http://www.yiiframework.com/doc/guide/1.1/en/topics.url

Well, you should read this : http://www.yiiframework.com/doc/guide/1.1/en/topics.url

Yii URL 管理非常方便,例如:

Yii URL management is quite handy, e.g. :

'urlManager'=>array(
  .....
  'rules'=>array(
    .....
    // AFTER other rules
    '<userName:.+>' => 'user/view',

Yii 将使用第一个匹配规则,因此您必须在此之前为其他控制器定义规则.

Yii will use the first matching rule, so you have to define rules for other controllers before this one.

在你的控制器中:

public function actionView($userName)
{
  // do what you want
}

这篇关于Yii URL 管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆