Home > Backend Development > PHP Tutorial > Summary of commonly used variables in yii templates_PHP tutorial

Summary of commonly used variables in yii templates_PHP tutorial

WBOY
Release: 2016-07-12 09:03:51
Original
1056 people have browsed it

A summary of commonly used variables in yii templates

A summary of some commonly used variables in yii templates.

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

The values ​​obtained through the following methods correspond to:

Home page 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 URL

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

Root directory address except domain name

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

Create url address

echo Yii::app()->createUrl('Site'); // /demos/helloworld/index.php?r=Site

URL except domain name

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

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

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

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

Render view (layout) $this->render('view', array('attribute1'=>'value1','attribute2'=>'value2'));

Jump page $this->redirect(array('route','attribute1'=>'value1','attribute2'=>'value2'));

Create widget $this->beginWidget(string $className, array $properties=array ( ))
             $this->endWidget();
 
Partial rendering renderPartial('view', array('attribute1'=>'value1','attribute2'=>'value2'));

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

js of framework/web/js/source, the files called by registerCoreScriptkey can be viewed in the framework/web/js/packages.php list

Method to get the ID of the current controller in the view: Yii::app()->getController()->id;

Get the ID method of the current action in the view: Yii::app()->getController()->getAction()->id;

yii gets the 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 the current home url: Yii::app()->homeUrl

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

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

1: 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; .

ext : points to the directory containing all third-party extensions; protectedextensions

Usage: Yii::getPathOfAlias('webroot')

Two: Get the current complete path

Yii::getFrameworkPath() :YII framework path

Three: Insert meta information

Yii::app()->clientScript->registerMetaTag('keywords','keyword');
Yii::app()->clientScript->registerMetaTag('description','Some description');
Yii::app()->clientScript->registerMetaTag('author','author');

Example:

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

Method to 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 physical path of the protected directory Yii::app()->basePath;

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

Articles you may be interested in

  • Yii framework module development analysis
  • Yii rules common verification rules memo
  • Understanding of Yii framework Yiiapp()
  • Summary of commonly used system variables in Thinkphp templates
  • Summary of common methods of Yii CDbCriteria
  • A summary of how to use database transactions in Yii
  • Using php functions in smarty templates and how to use multiple functions for one variable in smarty templates
  • A summary of common path methods in Yii

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1076539.htmlTechArticleSummary of commonly used variables in yii templates Summary of some commonly used variables in yii templates. There is such a url: http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx, which is obtained as follows...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template