& Amp; lt ;? PhpnamespaceHomeController; useHomeCommonBBaseController; classIndexControllerextendsBBaseController {code...} & amp; lt ;? PhpnamespaceHomeCommon; useThinkController; classBBaseController... Namespace Home \ Controller;
Use Home \ Common \ BBaseController;
Class IndexController extends BBaseController {
Public function _ construct () {parent ::__ construct ();} public function test () {echo "automatically calls the constructor of the parent class";} public function test2 () {echo "manual control does not call the constructor of the parent class ";}
}
Namespace Home \ Common;
Use Think \ Controller;
Class BBaseController extends Controller {
Public static $ login = true; // public function _ construct () {parent :__ construct (); $ this-> initialize ();}
Public function initialize () {if (! Session ("admin_home_user") {$ this-> error ("You have not logged on, please log on", "/Home/login", '3 ');}}
}
Reply content:
Namespace Home \ Controller;
Use Home \ Common \ BBaseController;
Class IndexController extends BBaseController {
Public function _ construct () {parent ::__ construct ();} public function test () {echo "automatically calls the constructor of the parent class";} public function test2 () {echo "manual control does not call the constructor of the parent class ";}
}
Namespace Home \ Common;
Use Think \ Controller;
Class BBaseController extends Controller {
Public static $ login = true; // public function _ construct () {parent :__ construct (); $ this-> initialize ();}
Public function initialize () {if (! Session ("admin_home_user") {$ this-> error ("You have not logged on, please log on", "/Home/login", '3 ');}}
}