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

Summary of common path methods in Yii_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:53:21
Original
781 people have browsed it

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
Copy after login

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');
Copy after login

Get the ID of the current controller in the view:

Yii::app()->getController()->id;
Copy after login

Get the ID method of the current action in the view:

Yii::app()->getController()->getAction()->id;
Copy after login

yii gets ip address

Yii::app()->request->userHostAddress;
Copy after login

yii determines whether the submission method is a post request

Yii::app()->request->isPostRequest
Copy after login

yii determines whether it is an ajax request

Yii::app()->request->isAjaxRequest
Copy after login

Get the current domain name:

Yii::app()->request->hostInfo
Copy after login

Get the physical path of the protected directory

YII::app()->basePath;
Copy after login

Get the url of the previous page to return

Yii::app()->request->urlReferrer;
Copy after login

Get the current url

Yii::app()->request->url;
Copy after login

Get current home url

Yii::app()->homeUrl
Copy after login

Get the current return url

Yii::app()->user->returnUrl
Copy after login

Project path

dirname(Yii::app()->BasePath)
Copy after login

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')
Copy after login

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 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