Create a public controller

We have created background verification, but we can still access it directly by directly entering the routing address. How should we solve this problem?

We use the __construct constructor, which can be called when the class is instantiated.

CommonController.class.php

<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends Controller
{
    public function __construct(){
        parent::__construct();
        if (!Session('uid')){
            $this->error('请先登录在访问',U('Login/index'));
        }
    }
}

We need to inherit this CommonController.class.php controller on each page

QQ截图20170622154616.png

At this time When we directly access the route, it will prompt

QQ截图20170621151016.png

#, so our public controller is completed.

Continuing Learning
||
<?php namespace Admin\Controller; use Think\Controller; class CommonController extends Controller { public function __construct(){ parent::__construct(); if (!Session('uid')){ $this->error('请先登录在访问',U('Login/index')); } } }
submitReset Code