This article mainly introduces thinkphp3.2.2 front-end and back-end public class architecture issues, and analyzes in detail the simple call methods of front-end and back-end public classes in the form of instances, which is of great practical value, for more information about thinkphp3.2.2, see the examples in this article. Share it with you for your reference. The specific analysis is as follows:
3.13 many projects used the front and back-end public classes before, and created the Baseaction under lib/action as the public inheritance class. it was found that many people in section 3.2.2 used the call, so that each time they used the call, it was very troublesome, xiao Bian is deliberately lazy. Use the following methods to solve the problem. If you are interested, you can improve it!
Thinkphp3.2.2 creates Application/Common/Controller/BaseController. class. php
The code is as follows:
<? Php
Namespace Common \ Controller;
Use Think \ Controller;
/**
* Frontend and backend public base classes
* Modify author: Jack
* Modify time: 2014-7-12
*/
Class BaseController extends Controller {
Public function _ initialize () {// global variable
Dump ('base class ');
$ This-> cfg ();
}
}
In Home/Controller/ZixunController. class. php
The code is as follows:
<? Php
Namespace Home \ Controller;
Use Common \ Controller \ BaseController;
Class ZixunController extends BaseController {
Public function index (){
$ Result = $ this-> lists ();
Dump ($ result );
}
}
Of course, you can also create your own base class in the front and back ends, such as setting up AdminController in the background. class. php inherits BaseController. class. php. create HomeController on the frontend. class. php inherits BaseController. class. each php module inherits its own base class, so that the project can be clearer and avoid repeated wheel creation, saving a lot of things. However, note that each class must declare a namespace, however, the resources used can be defined in their respective base classes without being written once. For example, if AdminController. class. php inherits BaseController. class. php, you do not need to write use Think \ Controller. you can simply use Common \ Controller \ BaseController.
I hope this article will help you with ThinkPHP framework programming.