think\Controller::__construct PHP Method

__construct() public method

架构函数
public __construct ( think\Request $request = null )
$request think\Request Request对象
    public function __construct(Request $request = null)
    {
        if (is_null($request)) {
            $request = Request::instance();
        }
        $this->view = View::instance(Config::get('template'), Config::get('view_replace_str'));
        $this->request = $request;
        // 控制器初始化
        $this->_initialize();
        // 前置操作方法
        if ($this->beforeActionList) {
            foreach ($this->beforeActionList as $method => $options) {
                is_numeric($method) ? $this->beforeAction($options) : $this->beforeAction($method, $options);
            }
        }
    }

Usage Example

コード例 #1
0
 public function __construct()
 {
     parent::__construct();
     if (!session('?username')) {
         $this->error('请先登录', U('login/login'), 3);
     }
 }
All Usage Examples Of think\Controller::__construct