BaseController.php 907 字节
<?php

namespace app\web\controller;

use think\Request;
use think\Session;
use think\Validate;
use think\Controller as thinkController;
use app\common\service\Render as RenderTrait;

class BaseController extends thinkController
{
    use RenderTrait;

    const SUCCESS_CODE = 0;

    /**
     * 登录验证
     */
    public function _initialize()
    {
        $user = Session::get('name');
        if($user === ''){
            // if (Session::get('name')) {
            return   Request::instance()->isAjax() ? json($this->renderError('您尚未登录系统')) : $this->redirect(url('web/index/login'));
        }
    }

    /**
     *  表单验证
     */

    public function formValidate($data, $rules, $message)
    {
        $validate = new Validate($rules, $message);

        if (!$validate->check($data)) {
            return $validate->getError();

        }

        return null;
    }

}