Ita*_*vka 12 php url url-routing yii
我正在使用Yii.
如果我的网址是http://localhost/evengee/event/page/id/2/sfn+master/?tab=3
我的真实网址(文件路径)只是http://localhost/evengee
我将如何获得,最好是在视图中:
http://localhost/evengee/event/page/id/2/sfn+master/?tab=3http://localhost/evengee/event/page/id/2/sfn+master/ 我知道我可以拆分/爆炸str_replace吗?并使用$ _SERVER.宁愿使用Yii本机方法.
Ita*_*vka 18
对于:
完整的URL(http://localhost/even/page/id/2/?t=3)使用
Yii::app()->request->getUrl(),
没有参数的URL(http://localhost/even/page/id/2/使用
Yii::app()->request->getPathInfo().
第二个将为您提供没有架构,服务器和查询字符串的URL.这似乎足够好了.
要获取完整的 URL,请使用getRequestUrl()以下方法CHttpRequest
Yii::app()->request->getRequestUrl();
您可以从 CApplication 方法获取当前页面的控制器、模块和操作名称
Yii::app()->getController()->id; //gets you the controller id
Yii::app()->getController()->getAction()->id; //gets you the action id
您可以使用 CApplication 的 baseURL 属性拼凑出一个 URL
Yii::app()->baseURL