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
At this time When we directly access the route, it will prompt
#, so our public controller is completed.