天天看点

YII 路径总结

如果是 // 就会默认去调 protected/views/layouts,//代表 绝对路径

其实 就是 绝对和相对的关系 /代表相对路径,如module/user下的layout

用单斜杠的话默认会先找当前已经激活的模块底下的view,若当前未有激活的模块则从系统根目录下开始找,双斜杠的话就直接从系统根下开始找

YII 路径总结

$this->renderpartial('application.modules.admin.views.product._search')  

yii framework已经定义的命名空间常量

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

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

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

webroot: 指向包含里入口脚本 文件的目录. 此别名自 1.0.3 版起生效. \

ext : 指向包含所有第三方扩展的目录, 从版本 1.0.8 可用;  \protected\extensions

YII 路径总结

yii::getpathofalias('zii')  

yii::import ('zii.*')   

yii::setpathofalias('backend', $backend);  

'import' => array(  

'backend.models.*',   

应用的主目录是指包含所有安全系数比较高的php代码和数据的根目录。在默认情况下,这个目录一般是入口代码所在目录的一个目录: protected 。这个路径可以通过在application configuration里设置 basepath来改变.

yii framework路径

YII 路径总结

yii::getframeworkpath()  

 yii 文件下载

YII 路径总结

yii::app()->getrequest()->sendfile('test.txt', 'file content goes here.');   

 protected/runtime

YII 路径总结

yii::app()->getruntimepath();  

protected/venders目录

YII 路径总结

yii::import('application.venders.*');    

或在protected/config/main.php说明

YII 路径总结

'import'=>array(    

        ......    

        'application.venders.*',    

    ),  

插入meta信息

YII 路径总结

yii::app()->clientscript->registermetatag('关键字','keywords');  

yii::app()->clientscript->registermetatag('一些描述','description');  

yii::app()->clientscript->registermetatag('作者','author');  

yii::app()->clientscript->registermetatag(' text/html;charset=utf-8', null, 'content-type');  

<link rel="alternate" type="application/rss+xml" href="http://www.dreamdu.com/feed/" />

YII 路径总结

yii::app()->clientscript->registerlinktag('alternate','application/rss+xml',$this->createurl('/feed'));  

YII 路径总结

yii::app()->clientscript->registercssfile(yii::app()->baseurl.'/css/my.css');  

yii::app()->clientscript->registerscriptfile(yii::app()->baseurl.'/css/my.js');  

<?php echo $this->module->assetsurl; ?>/css/main.css  

调用yii框架中framework/web/js/source的js,其中registercorescript key调用的文件在framework/web/js/packages.php列表中可以查看

YII 路径总结

yii::app()->clientscript->registercorescript('jquery');  

在view中得到当前controller的id方法:

YII 路径总结

yii::app()->getcontroller()->id;    

在view中得到当前action的id方法:

YII 路径总结

yii::app()->getcontroller()->getaction()->id;    

yii获取ip地址

YII 路径总结

yii::app()->request->userhostaddress;  

yii判断提交方式

YII 路径总结

yii::app()->request->ispostrequest isdeleterequest isajaxrequest  

得到当前域名:

YII 路径总结

yii::app()->request->hostinfo  

得到proteced目录的物理路径

YII 路径总结

yii::app()->basepath;  

得到模块名称

YII 路径总结

$module = yii::app()->getmodule()->getid();  

获得上一页的url以返回

YII 路径总结

yii::app()->request->urlreferrer;  

得到当前url

YII 路径总结

yii::app()->request->url;  

得到当前home url

YII 路径总结

yii::app()->homeurl  

得到当前return url

YII 路径总结

yii::app()->user->returnurl  

项目路径

YII 路径总结

dirname(yii::app()->basepath)  

yii::app()->getbaseurl(true);  

<?php echo $this->getlayoutfile('main'); ?>

$this->redirect('index.php?r=admin/manage');

{createurl()}

YII 路径总结

echo $this->createurl('urlboyleetest');  

//out => /yii_lab/index.php?r=lab/urlboyleetest  

$this->createurl('post/read') // /index.php/post/read  

YII 路径总结

<?php echo yii::app()->request->baseurl; ?>/css/screen.css  

yii::app()->theme->baseurl.'/images/filename.gif'    

{createabsoluteurl()}

YII 路径总结

echo $this->createabsoluteurl('urlboyleetest');  

//out => http://localhost/yii_lab/index.php?r=lab/urlboyleetest