[decided] - Call to a member function redirect() on string

Hello. I have a very old project in yii2. And recently I updated it to the latest version.

So, I have next code in my controller:

    public function beforeAction($action)
    {
        ...
        if (!Yii::$app->request->isAjax) {
            return $this->goBack();
        }
        ...
    }

And I see error: Call to a member function redirect() on string.

yii\web\Controller:

    public function goBack($defaultUrl = null)
    {
        return $this->response->redirect(Yii::$app->getUser()->getReturnUrl($defaultUrl));
    }

and $this->response it is a string.

Am I missing something?

If you have init method in your controller it must call parent::init().

1 Like

exactly. thanks you.