<?php namespace Home\Controller; use Home\Controller\BaseController; //引用BaseController类 class IndexController extends BaseController { //继承父类 public function index(){ echo session("uid"); } }
Base类:建立构造函数
<?php namespace Home\Controller; use Think\Controller; /** * */ class BaseController extends Controller { public function __construct() { parent::__construct();//调用父类构造函数 if(!session("?uid")){ //不存在,跳转到登录页面 $this->redirect(‘Login/login‘,array(),3,‘跳转中‘); exit; } } }