Yii的常用URL和渲染方法

当前页面url  Yii::app()->request->url;
跳转前一个页面url $this->redirect(Yii::app()->request->urlReferrer);
根目录URL Yii::app()->baseUrl 或 Yii::app()->request->baseUrl; 
自定义URL $this->createUrl('post/read',array('id'=>100))或Yii::app()->createUrl();

当前项目::Yii::getPathOfAlias('webroot');

主机:   Yii::app()->request->hostInfo         http://127.0.0.1

项目首页         Yii::app()->homeUrl            /blog/index.php

 

渲染视图 $this->render('view', array('attribute1'=>'value1','attribute2'=>'value2'));

创建小组件$this->beginWidget(string $className, array $properties=array ( ))
        $this->endWidget();

局部渲染 renderPartial('view', array('attribute1'=>'value1','attribute2'=>'value2'));

调用YII框架中jqueryYii::app()->clientScript->registerCoreScript('jquery');

 

view中得到当前controllerID方法Yii::app()->getController()->id;

view中得到当前actionID方法Yii::app()->getController()->getAction()->id;

 yii获取ip地址Yii::app()->request->userHostAddress;

 yii判断提交方式Yii::app()->request->isPostRequest 

得到当前域名: Yii::app()->request->hostInfo 

得到proteced目录的物理路径YII::app()->basePath;    

 获得上一页的url以返回Yii::app()->request->urlReferrer; 

 得到当前home url Yii::app()->homeUrl 

 得到当前return url Yii::app()->user->returnUrl 

 项目路径dirname(Yii::app()->BasePath) 

 

在Controller::action中,我们要输出一个链接,可以这样做:

$this->createUrl('actionName', array('params01'=>'value01', 'params02'=>'value02') );

//Controller::createUrl($route,$params=array(),$ampersand='&')

posted @ 2014-01-10 10:02  taoxiaodong  阅读(506)  评论(0编辑  收藏  举报