Summary of common variables in Yii templates
A summary of some of the variables commonly used in Yii templates.
Existing such a url:http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx
The values that are obtained in the following ways correspond to:
Home address except for 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 except domain name address
Echo Yii::app ()->homeurl; '/demos/helloworld/index.php '
Create a URL address
Echo Yii::app ()->createurl (' Site '); /demos/helloworld/index.php?r=site
URLs except for domain names
Yii::app ()->request->geturl ();
Jumps to the previous page URL $this->redirect (Yii::app ()->request->urlreferrer);
Jump 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 (' 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 the YII framework in Jquery:yii::app ()->clientscript->registercorescript (' jquery ');
Framework/web/js/source JS, where registercorescriptkey called files can be viewed in the framework/web/js/packages.php list
Get the ID of the current controller in view method: Yii::app ()->getcontroller ()->id;
Get the ID method of the current action in view: Yii::app ()->getcontroller ()->getaction ()->id;
YII Get IP Address: Yii::app ()->request->userhostaddress;
Yii Judgment Submission Method: Yii::app ()->request->ispostrequest
Get current domain name: Yii::app ()->request->hostinfo
Get the physical path to the proteced directory: Yii::app ()->basepath;
Get the URL of the previous page to return: Yii::app ()->request->urlreferrer;
Get current Url:yii::app ()->request->url;
Get current Home Url:yii::app ()->homeurl
Get current return Url:yii::app ()->user->returnurl
Project path: DirName (Yii::app ()->basepath)
One: 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 entry script file; .\
Ext: Point to the directory containing all third-party extensions; \protected\extensions
Usage: Yii::getpathofalias (' Webroot ')
Second: Get the current full path
Yii::getframeworkpath (): YII Framework Path
Three: inserting meta information
Yii::app ()->clientscript->registermetatag (' keywords ', ' keywords ');
Yii::app ()->clientscript->registermetatag (' description ', ' some descriptions ');
Yii::app ()->clientscript->registermetatag (' author ', ' author ');
Example:
Expressed as: Yii::app ()->clientscript->registerlinktag (' alternate ', ' Application/xml ', $this->createurl ('/feed ') );
Add a CSS file 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 ');
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::app ()->request->userhostaddress;
Yii Judgment Submission Method
Yii::app ()->request->ispostrequest
Get the physical path to the proteced directory Yii::app ()->basepath;
Project Path DirName (Yii::app ()->basepath)
Articles you may be interested in
- Analysis of module development of YII Framework Framework
- YII rules common validation Rule memo
- The understanding of Yii Framework Yiiapp ()
- Summary of System variables commonly used in thinkphp templates
- Summary of common methods of Yii Cdbcriteria
- Summary of usage methods of database transactions in Yii
- Use PHP functions in Smarty Templates and how to use multiple functions for a variable in a smarty template
- Summary of common path methods for Yii
http://www.bkjia.com/PHPjc/1076539.html www.bkjia.com true http://www.bkjia.com/PHPjc/1076539.html techarticle the common variables in yii templates summarize some variables commonly used in Yii templates. Existing such a url:http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx is obtained by the following way ...