PHP头条
热点:

yii模板中常用变量总结


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->returnUrl);

创建url地址 Yii::app()->createUrl('/',array('param1'=>'val'));  //  /demos/helloworld/index.php

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

跳转页面 $this->redirect(array('route','attribute1'=>'value1','attribute2'=>'value2'));

创建小组件$this->beginWidget(string $className, array $properties=array ( ))
          $this->endWidget();
   
局部渲染 renderPartial('view', array('attribute1'=>'value1','attribute2'=>'value2'));

调用YII框架中jquery:Yii::app()->clientScript->registerCoreScript('jquery');  
 
framework/web/js/source的js,其中registerCoreScriptkey调用的文件在framework/web/js/packages.php列表中可以查看
 
在view中得到当前controller的ID方法:Yii::app()->getController()->id;   
 
在view中得到当前action的ID方法: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;

得到当前url :Yii::app()->request->url;

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

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

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

一:Yii framework 已经定义的命名空间常量

system: 指向Yii框架目录;  Yii\framework

zii: 指向zii library 目录;  Yii\framework\zii

application : 指向应用程序基本目录;  protected\

webroot: 指向包含里入口脚本 文件的目录;  .\

ext : 指向包含所有第三方扩展的目录;  \protected\extensions
 
用法:Yii::getPathOfAlias('webroot')

二:取得当前的完整路径

Yii::getFrameworkPath()  :YII framework路径
 
三:插入meta信息

Yii::app()->clientScript->registerMetaTag('keywords','关键字');
Yii::app()->clientScript->registerMetaTag('description','一些描述');
Yii::app()->clientScript->registerMetaTag('author','作者');

示例:

表示为:Yii::app()->clientScript->registerLinkTag('alternate','application/xml',$this->createUrl('/feed'));
 
在控制器添加CSS文件或JavaScript文件

Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js'); 
 
在view中得到当前controller的ID方法

Yii::app()->getController()->id;

在view中得到当前action的ID方法

Yii::app()->getController()->getAction()->id;
 
Yii获取ip地址

Yii::app()->request->userHostAddress; 
 
Yii判断提交方式

Yii::app()->request->isPostRequest

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

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

您可能感兴趣的文章

  • Yii framework框架之模块开发分析
  • Yii rules常用验证规则备忘
  • Yii框架Yiiapp()的理解
  • Thinkphp 模板中常用的系统变量总结
  • Yii CDbCriteria的常用方法总结
  • Yii中的数据库事务的使用方法小结
  • smarty模板中使用php函数以及smarty模板中如何对一个变量使用多个函数
  • Yii常用路径方法总结

www.phpzy.comtrue/php/2184.htmlTechArticleyii模板中常用变量总结 yii模板中常用的一些变量总结。 现有这样一个url:http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx 则通过如下方式获取的值对应分别为: 除域名外的首页地址 ec...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐