YII路徑的用法總結(jié)
在yii中如果是 // 就會默認去調(diào) protected/views/layouts,//代表絕對路徑。這其實就是絕對和相對的關(guān)系 /代表相對路徑,如module/user下的layout。使用單斜杠的話默認會先找當前已經(jīng)激活的模塊底下的view,若當前未有激活的模塊則從系統(tǒng)根目錄下開始找,雙斜杠的話就直接從系統(tǒng)根下開始找
Yii framework已經(jīng)定義的命名空間常量:
system: 指向Yii框架目錄; YII\framework
zii: 指向zii library 目錄; YII\framework\zii
application: 指向應(yīng)用程序基本目錄; protected\
webroot: 指向包含里入口腳本文件的目錄. 此別名自 1.0.3 版起生效. \
ext: 指向包含所有第三方擴展的目錄, 從版本 1.0.8 可用; \protected\extensions
Yii::getPathOfAlias('zii') Yii::import ('zii.*') Yii::setPathOfAlias('backend', $backend); 'import' => array( 'backend.models.*',
應(yīng)用的主目錄是指包含所有安全系數(shù)比較高的PHP代碼和數(shù)據(jù)的根目錄。在默認情況下,這個目錄一般是入口代碼所在目錄的一個目錄: protected。這個路徑可以通過在application configuration里設(shè)置 basePath來改變.
YII framework路徑:
Yii::getFrameworkPath() {full URL}
http://localhost/yii_lab/index.php?r=lab/urlBoyLeeTest
protected/venders目錄:
Yii::import('application.venders.*');
或在protected/config/main.php說明:
'import'=>array( ...... 'application.venders.*', ),
插入meta信息:
Yii::app()->clientScript->registerMetaTag('keywords','關(guān)鍵字'); Yii::app()->clientScript->registerMetaTag('description','一些描述'); Yii::app()->clientScript->registerMetaTag('author','作者'); <link rel="alternate" type="application/rss+xml" href="http://www.dbjr.com.cn/" /> Yii::app()->clientScript->registerLinkTag('alternate','application/rss+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'); <?php echo $this->module->assetsUrl; ?>/css/main.css
調(diào)用YII框架中framework/web/js/source的js,其中registerCoreScript key調(diào)用的文件在framework/web/js/packages.php列表中可以查看:
Yii::app()->clientScript->registerCoreScript('jquery');
在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)
如果你自己有個目錄下有些類或文件常用,可以在main.php的最上邊定義一個路徑別名,別名可以被翻譯為其相應(yīng)的路徑。
Yii::getPathOfAlias('webroot')
如果是多個可以在main.php中的array中加一個配置
'aliases'=>array( 'local'=>'path/to/local/' ), <?php echo $this->getLayoutFile('main'); ?> $this->redirect('index.php?r=admin/manage'); {createUrl()} echo $this->createUrl('urlBoyLeeTest'); //out => /yii_lab/index.php?r=lab/urlBoyLeeTest $this->createUrl('post/read') // /index.php/post/read <?php echo Yii::app()->request->baseUrl; ?>/css/screen.css Yii::app()->theme->baseUrl.'/images/FileName.gif' {createAbsoluteUrl()} echo $this->createAbsoluteUrl('urlBoyLeeTest'); //out => http://localhost/yii_lab/index.php?r=lab/urlBoyLeeTest
相關(guān)文章
PhpStorm 如何優(yōu)雅的調(diào)試Hyperf的方法步驟
這篇文章主要介紹了PhpStorm 如何優(yōu)雅的調(diào)試Hyperf的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11配置Apache2.2+PHP5+CakePHP1.2+MySQL5運行環(huán)境
因為最近要用PHP做個小東西,新學(xué)了PHP。結(jié)果學(xué)PHP只用了2個小時,配置服務(wù)器卻用了兩天,郁悶得想罵人。為了避免以后忘掉,寫個博客留底。2009-04-04使用PHP Socket 編程模擬Http post和get請求
這篇文章主要介紹了使用PHP Socket 編程模擬Http post和get請求 ,需要的朋友可以參考下2014-11-11