Yii common path method summary _ PHP Tutorial

Source: Internet
Author: User
Summary of common Yii path methods. Summary of common path methods in Yii Framework. Add a CSS file or JavaScript file in the controller: Yii: app ()-clientScript-registerCss Yii common path method summary

Summary of some common path methods in the Yii Framework.

Add a CSS 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'); 
 module->assetsUrl; ?>/css/main.css

Call the js of framework/web/js/source in the YII framework. the file called by registerCoreScript key can be viewed in the framework/web/js/packages. php list:

Yii::app()->clientScript->registerCoreScript('jquery');

Obtain the ID method of the current controller in view:

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

Obtain the ID of the current action in the view:

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

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

Obtain the physical path of the proteced directory.

YII::app()->basePath;

Returns the url of the previous page.

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

Get the current url

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

Get the current home url

Yii::app()->homeUrl

Returns the current return url.

Yii::app()->user->returnUrl

Project path

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

If you have a directory that is commonly used in some classes or files, you can define a path alias at the top of main. php. the alias can be translated into the corresponding path.

Yii::getPathOfAlias('webroot')

You can add one configuration to multiple arrays in main. php.

Articles you may be interested in
  • Yii rules common verification rules memo
  • Summary of using database transactions in Yii
  • Yii View (output) the SQL statement executed on the current page
  • Yii database addition, modification, and deletion operations summary
  • How to configure the default controller and action in the yii Framework
  • Yii controller action parameter binding
  • Yii action methods and techniques
  • Yii database query operation summary

Summary of some common path methods in the policyii framework. Add a CSS file or JavaScript file in the controller: Yii: app ()-clientScript-registerCss...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.