tp6中间件不管用 可以直接读到控制器

浏览:1703 发布日期:2021/10/09
5.0.0 - 致命 - 未处理
<?php
declare (strict_types = 1);

namespace app\demo\controller;

use app\baseController;
use app\middleware\Auth;

class base extends baseController
{
protected $middleware = [Auth::class];

}


<?php
declare (strict_types = 1);

namespace app\demo\controller;

use think\App;

class Index extends base
{
public function __construct(App $app)
{
parent::__construct($app);
echo 123;
}

public function index()
{
return '您好!这是一个[demo]示例应用';
}
}




<?php
declare (strict_types = 1);

namespace app\middleware;

class Auth
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
//
return $this->jsonThrow('token失效');
return $next($request);
}

public static function jsonThrow(
$message = "fail",
$code = 40000,
$data = [],
$type = 'json',
$httpCode = 200,
$headers = []
) {
return response(self::renderArray($message, $code, $data), $httpCode, $headers, $type);
}

private static function renderArray($msg = '', $httpCode, $data = [])
{
$msg_data['code'] = $httpCode;
$msg_data['data'] = $data;
$msg_data['message'] = $msg;
if (env("app_debug") && !empty(request()->controller())) {
$msg_data['operate'] = app('http')->getName() . '/' . request()->controller() . '/' . request()->action();
}
return $msg_data;
}
}


这样写中间件没管用,控制器输出了.
评论(
后面还有条评论,点击查看>>