Home  >  Article  >  Backend Development  >  Summary of usage of YII path, summary of usage of YII path_PHP tutorial

Summary of usage of YII path, summary of usage of YII path_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:23:21940browse

Summary of usage of YII path, summary of usage of YII path

In Yii, if it is //, protected/views/layouts will be adjusted by default, // represents the absolute path. This is actually the relationship between absolute and relative / represents a relative path, such as layout under module/user. If a single slash is used, the view under the currently activated module will be searched first by default. If there is no currently activated module, the search will be started from the system root directory. If a double slash is used, the view will be searched directly from the system root

Namespace constants defined by Yii framework:

system: points to the Yii framework directory; YIIframework
zii: points to the zii library directory; YIIframeworkzii
application: points to the application base directory; protected
webroot: Points to the directory containing the entry script file. This alias is effective since version 1.0.3.
ext: points to the directory containing all third-party extensions, available since version 1.0.8; protectedextensions

Yii::getPathOfAlias('zii') 
Yii::import ('zii.*')  
Yii::setPathOfAlias('backend', $backend); 
'import' => array( 
'backend.models.*',  

The home directory of the application refers to the root directory that contains all PHP code and data with a relatively high security factor. By default, this directory is generally 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}

http://localhost/yii_lab/index.php?r=lab/urlBoyLeeTest 

protected/venders directory:

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

Or explain in protected/config/main.php:

'import'=>array(  
    ......  
    'application.venders.*',  
  ), 

Insert meta information:

Yii::app()->clientScript->registerMetaTag('keywords','关键字'); 
Yii::app()->clientScript->registerMetaTag('description','一些描述'); 
Yii::app()->clientScript->registerMetaTag('author','作者'); 
<link rel="alternate" type="application/rss+xml" href="http://www.bkjia.com/" />
Yii::app()->clientScript->registerLinkTag('alternate','application/rss+xml',$this->createUrl('/feed')); 

Add CSS files or JavaScript files in the controller:

Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css'); 
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js'); 
<&#63;php echo $this->module->assetsUrl; &#63;>/css/main.css 

Call the js of framework/web/js/source in the YII framework. The file called by the registerCoreScript key can be viewed in the framework/web/js/packages.php list:

Yii::app()->clientScript->registerCoreScript('jquery'); 

Get the ID of the current controller in the view:

Yii::app()->getController()->id;  

Get the ID of the current action in the view:

Yii::app()->getController()->getAction()->id;  

yii gets ip address

Yii::app()->request->userHostAddress; 

yii determines the submission method

Yii::app()->request->isPostRequest  

Get the current domain name:

Yii::app()->request->hostInfo 

Get the physical path of the protected directory

YII::app()->basePath; 

Get the url of the previous page to return

Yii::app()->request->urlReferrer; 

Get the current url

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

Get current home url

Yii::app()->homeUrl 

Get the current return url

Yii::app()->user->returnUrl 

Project path

dirname(Yii::app()->BasePath) 

If you have a directory with some commonly used classes or files, you can define a path alias at the top of main.php, and the alias can be translated into its corresponding path.

Yii::getPathOfAlias('webroot')  

If there are multiple, you can add a configuration in the array in main.php

'aliases'=>array( 
'local'=>'path/to/local/' 
), 
<&#63;php echo $this->getLayoutFile('main'); &#63;>
$this->redirect('index.php&#63;r=admin/manage');
{createUrl()}
echo $this->createUrl('urlBoyLeeTest'); 
//out => /yii_lab/index.php&#63;r=lab/urlBoyLeeTest 
$this->createUrl('post/read') // /index.php/post/read 
<&#63;php echo Yii::app()->request->baseUrl; &#63;>/css/screen.css 
Yii::app()->theme->baseUrl.'/images/FileName.gif'  
{createAbsoluteUrl()}
echo $this->createAbsoluteUrl('urlBoyLeeTest'); 
//out => http://localhost/yii_lab/index.php&#63;r=lab/urlBoyLeeTest 

How to use search in model in YII

There is no problem in writing this method, but if it is a multi-table joint query, it is not recommended to write it in the search method. When Yii automatically generates a model, it usually generates a search method, and the search method is generally used as a query for the model. That is, a separate table query.

If you want to query multiple tables together, it would be great to write another method! Moreover, the query method can be written in the action. There is no need to write the multi-table query in the model

Haha. The above is just a personal habit and is for reference only.

The query results returned by CActiveDataProvider usually obtain a list array through the getData method. There are many examples of yii on the Internet. You can understand it by just checking it

Yii login I want to use my own view template page, but I also want to reuse the verification login controller that comes with yii

Controller, model and view are inherently independent. You can just apply the view template you want. As long as you use Yii's CActiveForm widget in the view form, the verification function can be realized

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/840742.htmlTechArticleYII path usage summary, YII path usage summary in yii, if it is //, protected/ will be adjusted by default views/layouts, // represents the absolute path. This is actually the relationship between absolute and relative / generation...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn