Preface
The yiiwebController class is a commonly used class. Yii2’s front and back controllers all inherit this class. Regarding the description of the yiiwebController class, it is actually available in the Yii2 documentation. Why do I need to write this article? There may be many people wondering…. I think so. There is nothing wrong with the Yii2 documentation, but it is for the public after all, and there is no example in it. It is quite difficult for people to look at it. If someone can interpret each class and then release the specific Example, does it make you feel more comfortable just looking at it? Can you understand it faster?
Requirements analysis
Analyze the yiiwebController class and understand the methods and properties in its class and their usage.
Code analysis
Its inheritance order: `yiiwebController ? yiibaseController ? yiibaseComponent ? yiibaseObject
`
Interface implemented: yiibaseViewContextInterface
Its subclasses: yiirestActiveController, yiirestController
Take the WeelySummaryController controller as an example for testing , the following is the result I got from calling the more commonly used methods or attributes of its parent class, now I share it with you:
1. $this->id //Get the name string of the controller (controller id)
such as :weely-summary
2, $this->getViewPath() or $this->viewPath
//Get the current view path, specific to the folder name.
For example: D:phpStudyWWWhandbackendviewsweely-summary
3, $this->action->id //Get the current view name
For 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 and get the controller id and view id
For example: weely-summary/index
Related information
Yii2 documentation: http://www.yiichina.com/doc/api/ 2.0/yii-web-controller
The above has introduced the analysis of the yiiwebController class, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.