美文网首页
thinkphp5.1 初始化parent::initiali

thinkphp5.1 初始化parent::initiali

作者: 阿然学编程 | 来源:发表于2021-10-17 17:08 被阅读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();
    }

相关文章

网友评论

      本文标题:thinkphp5.1 初始化parent::initiali

      本文链接:https://www.haomeiwen.com/subject/sdunoltx.html