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::app()->request->getUrl();
跳转前一个页面url $this->redirect(Yii::app()->request->urlReferrer);
跳转当前页面url Yii::app()->request->redirect(Yii::app()->user->returnU