Can't set User- and MandatoryObject in a Session

3 years ago

thundervoice
Member | 11
+
0
-

I've tried to set in the UsersPresenter set the Session Object

$section = $this->session->getSection('user');
$section->user = "admin";

I like to set an Object that comes from the Database in the UserModel in a Session with:

Object that i need save in the Session for example:
$user->user_id
$user->user_name
$user->mandator_id
$user->mandator_name
etc.

$session->user = $user;

It doesn't Works this way.

Can you help me please?

Last edited by thundervoice (2016-03-08 17:16)

3 years ago

David Matějka
Moderator | 5892
+
0
-

What do you mean by “It doesn't Works this way.”?

Does it throw some error? or the user key is empty in a next request?

3 years ago

thundervoice
Member | 11
+
0
-

Yes, if i put out the $session throw it is empty with one Parameter:

$this->sendJson($session);
{warnOnUndefined:false}

I don't understand how i can set Parameters in the $session Object. In Simple PHP something like this:

$_SESSION['user_name'] = "admin";
$_SESSION['user_id'] = 12345;
etc.

This i need from the UserObject in Database.

Last edited by thundervoice (2016-03-08 17:27)

3 years ago

David Matějka
Moderator | 5892
+
0
-

you cannot send Session object this way, try this instead:

$this->sendJson(iterator_to_array($session));

3 years ago

thundervoice
Member | 11
+
0
-

Ohhhh… I've waste hours :)

Thx it works now.