Reputation: 774
I created a RegisterController
and after a successful registration I would like to forward the user back to the homepage, problem is, how can I pass a parameter to the homepage without using the redirect call to the controller because they display the long urls. I am passing parameter to the homepage so it could display that the user successfully registered on the site.
Tips please? Thanks.
Upvotes: 2
Views: 326
Reputation: 1579
You can pass array with redirect method like :
$data = array('data1'=>'data1', 'data2'=>'data2');
return $this->redirect(['site/dashboard', 'data' => $data]);
It could be very simple as you are thinking like redirection would be so long url and all.
Upvotes: 1
Reputation: 5515
yii\base\View has special $params property.
You can set it like this before rendering:
use Yii;
Yii::$app->view->params['customParam'] = 'customValue';
Inside a controller you can set it like this:
$this->view->params['customParam'] = 'customValue';
Then it will be available in views (including main layout):
/* @var $this yii\web\View */
echo $this->params['customParam'];
Upvotes: 0