Saving informations about user – I don't know how to do it

Notice: This thread is very old.
found
Member | 16
+
0
-

Hi,

I am really begginer, so I'm sorry if my problem is somewhere solved, I haven't found this solution or explanation in manual.

I have login application, autheticator etc. When a user is authenticated ( $this->getUser()->login(…); ) I have saved his ID and I could use

<?php
$id = $this->getUser()->getId();
?>

and then work with it. What I need now is to have saved his username. Is there any method how to save it and work with $this->getUser() ? E.g. $this->getNick(); ?

I had an idea to use $this->storage;, but I don't know how to work with this variable.

Thanks for responds,
Jimmy

enumag
Member | 2118
+
+1
-

In your authenticator you create an Identity object. You can store any additional data in it

new Identity($id, $roles, [ 'nick' => $nick ]);

and later retrieve them using

$this->getUser()->getIdentity()->nick;
found
Member | 16
+
0
-

Thank you, I thought I could use roles in some crazy ways, but this is exactly what I wanted, thanks again. :-)

Last edited by found (2014-09-26 00:25)