Analysis of common class architecture issues in thinkphp3.2.2 front and backend, thinkphp3.2.2 architecture_PHP tutorial

WBOY
Release: 2016-07-13 10:13:16
Original
908 people have browsed it

Analysis of thinkphp3.2.2 front-end and backend common class architecture issues, thinkphp3.2.2 architecture

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

Copy code The code is as follows:
namespace CommonController;
use ThinkController;
/**
* Common base classes for front and backend
* modify author: Jack
* modify time: 2014-7-12
*/
class BaseController extends Controller{
                             
          public function _initialize() {//Global variables
dump('base class');
$this->cfg();
}
}

In Home/Controller/ZixunController.class.php

Copy code The code is as follows:

namespace HomeController;
use CommonControllerBaseController;
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 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/917030.htmlTechArticleAnalysis of thinkphp3.2.2 front-end and back-end common class architecture issues, thinkphp3.2.2 architecture This article analyzes the thinkphp3.2.2 front-end and back-end with examples Public class architecture issues. Share it with everyone for your reference. Detailed analysis...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template