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)