首页 文章 Call to a member function re...

Call to a member function redirect() on string - Yii2 v2.0.36

发布时间:2021-01-28 14:31:23 作者:Soul-Yang 阅读量:1847


public 

function 
actionIndex(
)
{
    
$someCondition = myBoolFunction();
    
if (
$someCondition) {
        
return 
$this->redirect(
'my/url'));
    }
}
跳转时,可能报错:

Call to a member function redirect() on string


原因是:yii  v2.0.36  版本后需要在调用框架的parent::init() 之后调用,$this->redirect()  代码请看 
 
initialized there
.或如图



所以解决方法就是在调用跳转$this->redirect()前需要调用框架的init();建议在基础控制器里面的 beforeAction()里面添加,













  
留言
https://blog.key9.cn/
用户登录
您还没有写任何评论内容!
您已经评论过了!
只能赞一次哦!
您已经收藏啦!