Reputation: 17
I'm very new to Yii2 Framework. I want to pass variable from controller to view.
In controller:
public function actionDeleteAll(){
$var1 = 'abc';
return $this->redirect(array('index', 'var_view' => $var1 ));
}
In view:
<?php
echo $_GET['var_view'];
?>
But page show:
Upvotes: 0
Views: 983
Reputation: 815
Use render()
instead of redirect()
.
public function actionDeleteAll() {
$var1 = 'abc';
return $this->render('index', ['var_view' => $var1]);
}
Upvotes: 1
Reputation: 133400
if you really want a redirect to index .. passing the value in $var1 as var_view
public function actionDeleteAll(){
$var1 = 'abc';
return $this->redirect(array('index', 'var_view' => $var1 ));
}
be sure that your index have a proper signature eg:
public function actionIndex($var_view)
{
.... your code ..
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'var_view' => $var_view
]);
}
redirect work as function call so you must pass the proper param with corresponding param name
Upvotes: 1