如何在Yii中的模块中对beforeControllerAction()函数进行重定向?
问题描述:
I want to a redirect in this function. How can I do that?
I tried the following:
$this->owner->redirect(array("/myurl"));
Yii::app()-request->redirect('/myurl');
$this->redirect('/myurl');
none of them are working.
I tried with header('Location:myurl'); It works, but I don't want to use header in Yii php framework. Do you I have any idea?
答
If you want to redirect inside controller's action, use:
$this->redirect(Yii::app()->baseUrl.'/myurl');
$this
is your controller.
And If you want to redirect in somewhere elese(for example in components or extensions), use:
Yii::app()->controller->redirect(Yii::app()->baseUrl.'/myurl')
答
$this->redirect(Yii::App()->request->baseUrl.'/myurl');