Summary of usage of Yii path, summary of Yii path usage
In Yii, if yes//will default to the protected/views/layouts,//to represent the absolute path. This is actually the absolute and relative relationship/representing the relative path, such as layout under Module/user. Using a single slash, the default is to find the currently activated module under the view, if the current module is not active from the system root directory to find, double slash words directly from the system root to find
The YII framework has defined namespace constants:
system: Point to the YII framework directory; Yii\framework
zii: Point to zii Library directory; Yii\framework\zii
application: Point to the application base directory; protected\
Webroot: Point to the directory containing the inside portal script file. This alias is valid from version 1.0.3. \
ext: Point to the directory containing 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 application's home directory is the root directory of PHP code and data that contains all the higher safety factors. By default, this directory is usually a directory in the directory where the entry code is located: protected. This path can be changed by setting BasePath in the application configuration.
YII Framework Path:
Yii::getframeworkpath () {Full URL}
Protected/venders directory:
Yii::import (' application.venders.* ');
or in protected/config/main.php description:
' Import ' =>array (... ') Application.venders.* ',
Insert Meta Information:
Yii::app ()->clientscript->registermetatag (' keywords ', ' keywords '); Yii::app ()->clientscript->registermetatag (' description ', ' some descriptions '); Yii::app ()->clientscript->registermetatag (' author ', ' author ');
Add a CSS file or JavaScript file to the controller:
Call the Framework/web/js/source JS in the Yii framework, where the file Registercorescript key is called in the framework/web/js/packages.php list to see:
Get the ID method of the current controller in view:
Yii::app ()->getcontroller ()->id;
Get the ID method of the current action in view:
Yii::app ()->getcontroller ()->getaction ()->id;
Yii Get IP Address
Yii Judgment Submission Method
Yii::app ()->request->ispostrequest
Get the current domain name:
Get the physical path to the proteced directory
Get the URL of the previous page to return
Get current URL
Get the current home URL
Get the current return URL
Project path
If you own a directory where some classes or files are commonly used, you can define a path alias at the top of the main.php, and the alias can be translated to its corresponding path.
Yii::getpathofalias (' Webroot ')
If more than one configuration can be added to an array in the 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 '
How to use search in the model in Yii
You write this method is not a problem, but if it is multi-table, not recommended to write in the search method, Yii automatically generated model when the search method is generally generated, search method is generally used as the model query, that is, a separate table query.
If more than one table to check, then write a method how good ah! Moreover, the query method is written in the action, multi-table query is not necessary to write in the model AH
haha above is only personal habits for reference only.
Cactivedataprovider returned query results, generally through the GetData method to obtain a list array, the example of online yii many, landlord casually check to understand
Yii login I want to use my own view template page, but want to re-use Yii's own authentication login controller
Controller, model and view are independent, you can directly apply the view template you want, as long as the view form using Yii's Cactiveform widget to implement the verification function
http://www.bkjia.com/PHPjc/840742.html www.bkjia.com true http://www.bkjia.com/PHPjc/840742.html techarticle Yii Path Usage Summary, Yii path Usage summary in Yii If yes//will default to tune protected/views/layouts,//represents absolute path. This is in fact the absolute and relative relationship/generation ...