We are developing a site using ZendFrame work.
We need to set a auth variable(role) to manage user-type.
For that we use a variable this->view->auth->getIdentity()->role
to manage user-type.
In one chase we are trying to assign the user-type statically.
What is the code to assign the auth variable 'role'.
We tried with this->view->auth->getIdentity()->role = 'test'
, but it through warning.
The following should allow you to create a new Zend_Auth
identity upon successful login :
$identity = Zend_Auth::getInstance()->getStorage();
$identity->write($userData);
As for the user data, I usually store the database row corresponding to the user with the required fields like Name, surname, email, role, to name a few. If you store a Zend_Db_TableRow
in the Zend_Auth
you will be able to access it like this :
Zend_Auth::getInstance()->getIdentity()->role;
Quick reminder on Zend_Auth
:
$auth = Zend_Auth::getInstance(); // get the `Zend_Auth` instance (build on the singleton pattern)
$auth->hasIdentity(); // return true if an indentity exists and false if it doesn't
$auth->getIdentity(); // allow you to get the identity content (array, Zend_Db_TableRow and such)
$auth->write($data): // allow to create a new identity
$auth->clearIdentity(); // destroy any content stored in the identity. Zend_Session::destroy() can also be used since identity is stored in a session variable
For more you can read the official documentation : Zend_Auth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With