I am using Yii framework for my project;
I am redirecting page after success of insertion in database to another controller using
$this->redir
To redirect into same action with the all parameters that already have this works for me.
$this->redirect($_PHP['SELF']);
You can only pass GET parameters in the Yii 2 redirect()
. However, I had a similar situation and I resolved it by using Session storage.
Naturally, you can access current Session via Yii::$app->session
. Here is an example of using it in two separate controller actions:
public function actionOne() {
// Check if the Session is Open, and Open it if it isn't Open already
if (!Yii::$app->session->getIsActive()) {
Yii::$app->session->open();
}
Yii::$app->session['someParameter'] = 'Bool/String/Array...';
Yii::$app->session->close();
$this->redirect(['site/two']);
}
public function actionTwo() {
if (isset(Yii::$app->session['someParameter']) {
$param = Yii::$app->session['someParameter'];
} else {
$param = null;
}
$this->render('two', [
'param' => $param
]);
}
So now you should be able to access $param
inside the two
view.
For more information, please refer to the official class documentation.
Try:
$this->redirect(array('controller/action', 'param1'=>'value1', 'param2'=>'value2',...))
api yii 1, api yii 2
try this:
Yii::$app->response->redirect(['site/dashboard','id' => 1, 'var1' => 'test']);