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常用路径方法总结
http://www.bkjia.com/phpjc/1076539.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1076539.htmltecharticleyii模板中常用变量总结 yii模板中常用的一些变量总结。 现有这样一个url:http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx 则通过如下方式获...
