thinkphp3.2.2 Common class architecture problem analysis, thinkphp3.2.2 architecture
In this paper, the common class architecture of thinkphp3.2.2 is analyzed. Share to everyone for your reference. The specific analysis is as follows:
Before 3.13 Many projects all use the front and back common class, under Lib/action creates the baseaction as the public inherits the class, discovers 3.2.2 inside many people all use a call, so every use once to use a call, good trouble, small part deliberately lazy. The pro-test is resolved using the following methods. Interested friends can be enhanced to improve it!
thinkphp3.2.2 's so created application/common/controller/basecontroller.class.php
Copy the Code code as follows: <?php
namespace Common\controller;
Use Think\controller;
/**
* Front and rear common base class
* Modify Author:jack
* Modify Time:2014-7-12
*/
Class Basecontroller extends controller{
Public Function _initialize () {//global variable
Dump (' base class ');
$this->cfg ();
}
}
In the home/controller/zixuncontroller.class.php
Copy the Code code as follows:
<?php
namespace Home\controller;
Use Common\controller\basecontroller;
Class Zixuncontroller extends Basecontroller {
Public Function index () {
$result = $this->lists ();
Dump ($result);
}
}
Of course, in front of the background can also create their own base class, such as the background built AdminController.class.php inherit BaseController.class.php, The foreground creates HomeController.class.php inheritance BaseController.class.php each module inherits its own base class, so the project can be clearer, avoids duplicating wheels, saves a lot of things, but it must be noted that each class must declare a namespace, but the resources used can After being defined in the respective base class, you do not have to write once. For example, AdminController.class.php inherit BaseController.class.php, you do not have to write the use of Think\controller, directly using uses Common\controller\ Basecontroller can do it.
It is hoped that this article will be helpful to everyone's thinkphp framework design.
http://www.bkjia.com/PHPjc/917030.html www.bkjia.com true http://www.bkjia.com/PHPjc/917030.html techarticle thinkphp3.2.2 Common class architecture problem analysis, thinkphp3.2.2 architecture in this paper, we analyze the common class architecture problem of thinkphp3.2.2 and fore and aft platform. Share to everyone for your reference. Specific analysis ...