thinkphp5.1 初始化parent::initiali

2021-10-17  本文已影响0人  阿然学编程

因为初始化方法内return是无效的,所以使用send(),配合exit()解决

    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETE');
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Allow-Headers: Accept, Authorization, Origin, token, DNT, Cache-Control, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With, X-Mx-ReqToken, Keep-Alive, User-Agent,x-access-sign, x-access-time');
        header('X-Powered-By: WAF/2.0');
        if (request()->isOptions()) {
            exit();
        }
        //调用
        $this->checkTokens();
    }

    public function test()
    {
        ResJsonData::JsonData(1111)->send();
        exit();
    }
上一篇 下一篇

猜你喜欢

热点阅读