[英]yii2 - redirect from view to another view
I am trying to redirect from a View to another View and I cannot find a solution online. 我正在尝试从View重定向到另一个View,我无法在线找到解决方案。
I have tried using: 我尝试过使用:
Yii::$app->request->redirect(Yii::$app->createAbsoluteUrl("site/view"));
But I receive the following error: 但是我收到以下错误:
Unknown Method – yii\\base\\UnknownMethodException
未知方法 - yii \\ base \\ UnknownMethodException
Calling unknown method: yii\\web\\Application::createAbsoluteUrl()
调用未知方法:yii \\ web \\ Application :: createAbsoluteUrl()
You should use response
instead of request
: 您应该使用
response
而不是request
:
Yii::$app->response->redirect(['site/view']);
You can also use Url
helper to get an absolute url : 您还可以使用
Url
helper获取绝对URL:
Yii::$app->response->redirect(Url::to(['site/view'], true));
And if you want to use createAbsoluteUrl()
: 如果你想使用
createAbsoluteUrl()
:
Yii::$app->response->redirect(Yii::$app->urlManager->createAbsoluteUrl(['site/view']));
If you use $app then use it always use 如果你使用$ app然后使用它总是使用
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']));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.