Home >Backend Development >PHP Tutorial >Summary of common path methods in Yii_PHP tutorial

Summary of common path methods in Yii_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 09:53:21779browse

A summary of common path methods in Yii

A summary of how to use some common path methods in the Yii framework.

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'); 
<?php echo $this->module->assetsUrl; ?>/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 method of the current action in the view:

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

yii gets ip address

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

yii determines whether the submission method is a post request

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

yii determines whether it is an ajax request

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

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 configurations, you can add a configuration to the array in main.php.

Articles you may be interested in

  • Yii rulesCommon verification rules memo
  • Summary of how to use database transactions in Yii
  • Yii View (output) the sql statement executed on the current page
  • yii Database addition, modification, deletion related operations summary
  • How to configure the default controller and action in the yii framework
  • Yii controller action Parameter binding processing
  • Yii action method skills
  • Yii database query operation summary

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1003467.htmlTechArticleA summary of common path methods in Yii A summary of how to use some common path methods in the Yii framework. Add CSS files or JavaScript files in the controller: Yii::app()-clientScript-registerCss...
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