yii模板中常用的一些变量总结。
现有这样一个url:http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx
则通过如下方式获取的值对应分别为:
除域名外的首页地址
echo Yii::app()->user->returnUrl; // '/demos/helloworld/index.php'
当前页面url
echo Yii::app()->request->url; // '/demos/helloworld/index.php/xxx/xxx'
当前域名
echo Yii::app()->request->hostInfo; // 'http://www.phpernote.com/'
根目录URL
echo Yii::app()->request->baseUrl; // '/demos/helloworld'
除域名外的根目录地址
echo Yii::app()->homeUrl; // '/demos/helloworld/index.php'
创建url地址
echo Yii::app()->createUrl('Site'); // /demos/helloworld/index.php?r=Site
除域名外的URL
Yii::ap
本文总结了Yii框架中模板常用变量的使用,包括获取URL、域名、根目录、控制器ID、动作ID、IP地址等,并介绍了如何创建URL、渲染视图、注册JS及CSS文件、处理请求方式等。
订阅专栏 解锁全文

548

被折叠的 条评论
为什么被折叠?



