namespace Home\Controller;
use Home\Common\BBaseController;
class IndexController extends BBaseController{
public function __construct(){ parent::__construct();}public function test(){ echo "自動調用父類的構造方法";}public function test2(){ echo "人為控制不去調用父類的構造方法";}
}
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("您還沒有登入,請登入","/Home/login",'3'); }}
}
回複內容:
namespace Home\Controller;
use Home\Common\BBaseController;
class IndexController extends BBaseController{
public function __construct(){ parent::__construct();}public function test(){ echo "自動調用父類的構造方法";}public function test2(){ echo "人為控制不去調用父類的構造方法";}
}
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("您還沒有登入,請登入","/Home/login",'3'); }}
}