Home >Backend Development >PHP Tutorial >Analysis of common class architecture issues in thinkphp3.2.2 front and backend, thinkphp3.2.2 architecture_PHP tutorial
This article analyzes the front-end and back-end common class architecture issues of thinkphp3.2.2 with examples. Share it with everyone for your reference. The specific analysis is as follows:
Before 3.13, many projects used common front-end and back-end classes. I created Baseaction as a public inheritance class under lib/action. I found that many people in 3.2.2 used A to call it, so I had to use A to call it every time, which was very troublesome. , the editor is deliberately lazy. Personal test uses the following method to solve it. Interested friends can enhance and improve it!
thinkphp3.2.2 creates Application/Common/Controller/BaseController.class.php like this
In Home/Controller/ZixunController.class.php
public function index() {
$result = $this->lists();
dump($result);
}
}
Of course, you can also create your own base class in the front and backend. For example, if you create AdminController.class.php in the backend and inherit BaseController.class.php, and in the frontend you create HomeController.class.php and inherit BaseController.class.php, each module inherits its own base. Class, this way the project can be clearer, avoid reinventing the wheel, and save a lot of things. However, it must be noted that each class must declare a namespace, but the resources used can be defined in their respective base classes without having to write them again later. For example, if AdminController.class.php inherits BaseController.class.php, there is no need to write use ThinkController. Just use use CommonControllerBaseController.
I hope this article will be helpful to everyone’s ThinkPHP framework programming.