I am trying to redirect from a View to another View and I cannot find a solution online.
I have tried using:
Yii::$app->request->redirect(Yii::$app->createAbsoluteUrl("site/view"));
But I receive the following error:
Unknown Method – yii\base\UnknownMethodException
Calling unknown method: yii\web\Application::createAbsoluteUrl()
You should use response
instead of request
:
Yii::$app->response->redirect(['site/view']);
You can also use Url
helper to get an absolute url :
Yii::$app->response->redirect(Url::to(['site/view'], true));
And if you want to use createAbsoluteUrl()
:
Yii::$app->response->redirect(Yii::$app->urlManager->createAbsoluteUrl(['site/view']));
If you use $app then use it always use
Yii::$app->request->redirect(Yii::$app->createAbsoluteUrl("site/hat"));
instead of
Yii::$app->request->redirect(Yii::app()->createAbsoluteUrl("site/hat"));
or you can use this for get the url
Yii::$app->request->redirect(['site/hat']));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With