Yii2 Call to a member function validateCsrfToken() on string

Do you have an init(); in your SiteController?

If so you need to call parent::init();

 

 

错误已经定位,这个是yii2更新导致的问题:https://github.com/yiisoft/yii2/blob/master/framework/base/Controller.php#L105

yii2加入类变量 $request , 在init函数中初始化,因此如果重写controller的init方法,必须执行 parent:init(); , 否则就会出这个报错,而fecmall的有一些controller重新init方法,但是没有执行 parent:init;导致的controller 中的$this->request没有初始化导致的问题。

参考:http://www.fecmall.com/topic/4317 https://github.com/yiisoft/yii2/issues/18154

posted @ 2021-02-24 20:48  码农编程进阶笔记  阅读(170)  评论(0编辑  收藏  举报
返回顶部 有事您Q我