公共模板
<?php namespace appadmincommon; use thinkController; use thinkSession; /*公共控制器(home控制器)*/ class Base_home extends Controller { function _initialize(){ parent::_initialize(); //如果没有session if(!Session::has('admin')){ $this->error('未登录,无权访问···','login/index'); } } }
要求登录才能访问的控制器
<?php namespace appadmincontroller; use appadmincommonBase_home; class Home extends Base_home { public function index() { return $this->fetch(); } public function welcome() { return $this->fetch(); } }
这样一来:
如果非法访问