We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Save model fields data only

Hi guys!

Tell me please, how save model data only to session, without metadata and other data?

$user = Users::findFirst($user_id);
$session->set('user', $user);

$user contains many unnecessary to store information. I need only the field values from the model. And it takes up much space.

Sorry for my english dialect :)



85.5k
Accepted
answer
$session->set('user', $user->toArray());

?

Hmm.. its really. Thanks!

Also as ang argument for toArray method you can puts an array with columns you only need.

Hmm.. its really. Thanks!

Wojciech Ślawski, thanks too.