以下應允許您創建成功登錄後新Zend_Auth
身份:
$identity = Zend_Auth::getInstance()->getStorage();
$identity->write($userData);
對於用戶數據,我通常存儲與用戶提供類似名稱必填字段的數據庫行,姓,電子郵件,角色等等。如果您存儲在Zend_Db_TableRow
的Zend_Auth
,你將能夠訪問它是這樣的:
Zend_Auth::getInstance()->getIdentity()->role;
快速提醒在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
欲瞭解更多,你可以閱讀官方文檔:Zend_Auth