Anatomy of the Yiiwebcontroller class

Source: Internet
Author: User
Preface

The Yii\web\controller class is a more commonly used class, and the Yii2 controller inherits this class. About the Yii\web\controller class, in fact, YII2 document also has, why should I write this article? There may be a lot of people wondering .... I think so, Yii2 the document is there is no mistake, but that is for the public, and there is no instance, let people look at or is more laborious, if someone can read every class, and then release specific examples, is it more comfortable to look at it? Do you understand more quickly?

Demand analysis

Parses the Yii\web\controller class to understand the methods and properties in its class and their use.

Code Analysis

Its order of succession: ' Yii\web\controller? Yii\base\controller? Yii\base\component? Yii\base\object
`
Interfaces implemented:yii\base\ViewContextInterface

Its sub-class:yii\rest\ActiveController, yii\rest\Controller

Taking the Weelysummarycontroller controller as an example, the following is the result of the method or property that I call the parent class for more common use, and is now shared with you:

1, $this->id//Get the name string of the controller (Controller ID)
such as: Weely-summary

2, $this->getViewPath() 或者 $this->viewPath //Get the current view path, specific to the folder name.
Such as:D:\phpStudy\WWW\hand\backend\views\weely-summary

3, $this->action->id//Get the current view name
Example: Index//List page

4, $this->action->actionmethod//Get the current method name
such as: Actionindex

5, $this->actionparams//Bind the parameters of the current operation
such as: Array ([id] = 3)

6, $this->route//Get the route of the current request, get the controller ID and the view ID
such as: Weely-summary/index

Related information

YII2 's Documentation: Http://www.yiichina.com/doc/api/2.0/yii-web-controller

The above describes the analysis of the Yii\web\controller class, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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