This article describes how to use the YII path. For more information, see
This article describes how to use the YII path. For more information, see
In yii, if it is //, protected/views/layouts is called by default. // indicates the absolute path. This is actually the absolute and relative relationship/Represents the relative path, such as layout under module/user. If a single slash is used, the view under the activated module is first searched by default. If no activated module is found, the view is located in the system root directory, if the double slash is used, you can directly find it from the system root.
The namespace constants defined by Yii framework:
System: points to the Yii framework directory; YII \ framework
Zii: pointing to the zii library directory; YII \ framework \ zii
Application: points to the basic application directory; protected \
Webroot: point to the directory containing the script file. This alias takes effect from version 1.0.3 .\
Ext: points to a directory that contains all third-party extensions, available from version 1.0.8; \ protected \ extensions
Yii: getPathOfAlias ('zii') Yii: import ('zii. * ') Yii: setPathOfAlias ('backend', $ backend); 'import' => array ('backend. models. *',
The main directory of an application is the root directory that contains all PHP code and data with a high security factor. By default, this directory is usually a directory of the entry code Directory: protected. This path can be changed by setting basePath in application configuration.
YII framework path:
Yii: getFrameworkPath () {full URL}
? R = lab/urlBoyLeeTest
Protected/venders directory:
Yii: import ('application. venders .*');
Or in protected/config/main. php:
'Import' => array (... 'application. venders .*',),
Insert meta information:
Yii: app ()-> clientScript-> register1_ag ('keyword', 'keyword '); Yii: app ()-> clientScript-> register1_ag ('description ', 'Some description'); Yii: app ()-> clientScript-> register1_ag ('author', 'author '); Yii: app ()-> clientScript-> registerLinkTag ('alternet', 'application/rss + xml', $ this-> createUrl ('/feed '));
Add a CSS or JavaScript file to the Controller:
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
Call the js of framework/web/js/source in the YII framework. The file called by registerCoreScript key can be viewed in the framework/web/js/packages. php list:
Yii: app ()-> clientScript-> registerCoreScript ('jquery ');
Obtain the ID method of the current controller in view:
Yii: app ()-> getController ()-> id;
Obtain the ID of the current action in the view:
Yii: app ()-> getController ()-> getAction ()-> id;
Yii get IP Address
Yii: app ()-> request-> userHostAddress;
Yii judgment submission method
Yii: app ()-> request-> isPostRequest
Get the current domain name:
Yii: app ()-> request-> hostInfo
Obtain the physical path of the proteced directory.
YII: app ()-> basePath;
Returns the url of the previous page.
Yii: app ()-> request-> urlReferrer;
Get the current url
Yii: app ()-> request-> url;
Get the current home url
Yii: app ()-> homeUrl
Returns the current return url.
Yii: app ()-> user-> returnUrl
Project path
Dirname (Yii: app ()-> BasePath)
If you have a directory that is commonly used in some classes or files, you can define a path alias at the top of main. php. the alias can be translated into the corresponding path.
Yii: getPathOfAlias ('webroot ')
You can add one or more configurations to the array in main. php.
'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 =>? R = lab/urlBoyLeeTest