Common variables in yii templates _ PHP Tutorial

Source: Internet
Author: User
Summary of common variables in the yii template. Summary of common variables in the yii template some common variables in the yii template. There is a url like this: www. phpernote. comdemoshelloworldindex. phpxxxxxx, which summarizes common variables in the yii template using the following method:

Summary of common variables in the yii template.

There is such a url: http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx

The values obtained in the following way are:

Home address except domain name

Echo Yii: app ()-> user-> returnUrl; // '/demos/helloworld/index. php'

Current page url

Echo Yii: app ()-> request-> url; // '/demos/helloworld/index. php/xxx/xxx'

Current domain name

Echo Yii: app ()-> request-> hostInfo; // 'http: // www.phpernote.com /'

Root Directory URL

Echo Yii: app ()-> request-> baseUrl; // '/demos/helloworld'

Root Directory address except domain name

Echo Yii: app ()-> homeUrl; // '/demos/helloworld/index. php'

Create url

Echo Yii: app ()-> createUrl ('site'); // demos/helloworld/index. php? R = Site

URL except domain name

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

Jump to the url of the previous page $ this-> redirect (Yii: app ()-> request-> urlReferrer );

Jump to the current page url Yii: app ()-> request-> redirect (Yii: app ()-> user-> returnUrl );

Create url Yii: app ()-> createUrl ('/', array ('param1' => 'Val '); // demos/helloworld/index. php

Rendering view (layout) $ this-> render ('View', array ('bubute1' => 'value1 ', 'bubute2' => 'value2 '));

Jump to the page $ this-> redirect (array ('Route ', 'bubute1' => 'value1', 'bubute2' => 'value2 '));

Create a widget $ this-> beginWidget (string $ className, array $ properties = array ())
$ This-> endWidget ();

Partial rendering renderPartial ('View', array ('bubute1' => 'value1 ', 'bubute2' => 'value2 '));

Call jquery: YII: app ()-> clientScript-> registerCoreScript ('jquery ') in the Yii Framework ');

Framework/web/js/source js. the file called by registerCoreScriptkey can be viewed in the framework/web/js/packages. php list.
 
In the view, obtain the current controller ID method: Yii: app ()-> getController ()-> id;
 
Obtain the ID of the current action in the view: Yii: app ()-> getController ()-> getAction ()-> id;
 
Yii: Yii: app ()-> request-> userHostAddress;

Yii judgment submission method: Yii: app ()-> request-> isPostRequest
 
Obtain the current domain name: Yii: app ()-> request-> hostInfo

Obtain the physical path of the proteced Directory: YII: app ()-> basePath;
 
Get the url of the previous page to return: Yii: app ()-> request-> urlReferrer;

Obtain the current url: Yii: app ()-> request-> url;

Obtain the current home url: Yii: app ()-> homeUrl.

Get the current return url: Yii: app ()-> user-> returnUrl

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

I. 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 ;.\

Ext: points to the directory containing all third-party extensions; \ protected \ extensions
 
Usage: Yii: getPathOfAlias ('webroot ')

II. obtain the current complete path

Yii: getFrameworkPath (): YII framework path
 
3. Insert meta information

Yii: app ()-> clientScript-> register1_ag ('keyword', 'key ');
Yii: app ()-> clientScript-> register1_ag ('Description', 'Some description ');
Yii: app ()-> clientScript-> register1_ag ('author', 'author ');

Example:

Yii: app ()-> clientScript-> registerLinkTag ('alternet', 'application/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 ');
 
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

Obtain the physical path Yii: app ()-> basePath of the proteced directory;

Project path dirname (Yii: app ()-> basePath)

Articles you may be interested in
  • Module development and analysis of Yii framework
  • Yii rules common verification rules memo
  • Yii Framework Yiiapp ()
  • Summary of common system variables in Thinkphp templates
  • Summary of common Yii CDbCriteria methods
  • Summary of using database transactions in Yii
  • Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
  • Summary of common Yii path methods

Summary of variables commonly used in policyii templates. There is a url like this: the http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx gets it in the following way...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.