T
T
tkirsan4ik2016-08-09 08:49:06
Yii
tkirsan4ik, 2016-08-09 08:49:06

How to automatically load data from model into session in yii2?

Is there a function (magic, probably) (probably, you want something like $model->load($post), only in the opposite direction) that can load all the data from the AR model into the session (or into any variable)? Or just loop over all the attributes?

$ses = Yii::$app->session;
$ses->open();
//И тут вопросы...
$ses->close();

If not one or the other, please tell me the true method for solving this problem.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-08-09
@tkirsan4ik

There is no such possibility in the standard functionality, but it is easy to implement, for example:
Load data from the model into the session
Save data from session to model

$model->setAttributes(Yii::$app->session->get('model-key', []));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question