在Controller
控制器下新建Common.php
:
<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Db;
class Common extends Controller
{
//检查是否登录
public function _initialize()
{
if(!session('uname')){
$this->error('请先登录!',url('/admin/login/index'));
}
}
}
在需要判断登录的类中继承该类:
Index.php
:
<?php
namespace app\admin\controller;
/**
* Created by PhpStorm.
* User: gao
* Date: 2019/6/11
* Time: 15:39
*/
use think\Controller;
use think\Db;
class Index extends Common
{
//框架应用
public function Index(){
return view("index");
}
/**
* 文章内容显示
*/
public function AList(){
$sou = request()->param();
$name = input('tid') ? input('title') : ($sou['title'] = '');
//判断是不是第一栏目
$t_fid = input('t_fid') ? input('t_fid') : 0;
$Z_tid = 2;
if(isset($_POST['sousuo'])){
$tid = input("tid")