thinkphp3.2.2 Common class schema problem, thinkphp3.2.2 public
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. Welcome to Strengthen
thinkphp3.2.2 's so created application/common/controller/basecontroller.class.php
1
PHP 2namespace Common\controller; 3 Use Think\controller; 4 /* * 5 * Front and rear common base class 6 * Modify Author:jack 7 * Modify time:201 4-7-12 8 * / 9 classextends Controller {ten-one public function _initialize () {// Global Variables a Dump (' base class '); - $this, CFG (); - }
In the home/controller/zixuncontroller.class.php
Phpnamespace Home\controller; Use Common\controller\basecontroller; class extends Basecontroller { publicfunction 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.
http://www.bkjia.com/PHPjc/916820.html www.bkjia.com true http://www.bkjia.com/PHPjc/916820.html techarticle thinkphp3.2.2 Common class schema problems before and after thinkphp3.2.2 public 3.13 Many projects use both front and back common classes, create baseaction as public inheriting classes under Lib/action, Discover ...