我有一个奇怪的问题,我似乎无法追踪。我有一个自定义类(“Person”)扩展 Zend_Db_Table_Row_Abstract 代表一个用户。除其他外,此类具有在 init() 方法中设置的自定义变量,例如:
class Person extends Zend_Db_Table_Row_Abstract
{
protected $_cdata = array(); // non-db-table data gets put here through __set()
public function init()
{
$this->fullName = $this->firstName." ".$this->lastName; // this is saved to $this->_cdata['fullName']
}
登录后,我将此类的一个对象存储为 Zend Auth Identity:
$r = $auth->authenticate($authAdapter);
if($r->isValid())
{
$user = $db->getUserByEmail($email); // Retrieves an object of class "Person"
$auth->getStorage()->write($user);
}
现在,如果我在与登录相同的操作请求中调用 Auth Identity,它将正常工作:
echo $user->fullName; // Will print "John Smith" or whatever it is
但是,当我调用另一个操作并调用 Auth Identity 时,我会丢失存储在“_cdata”数组中的所有内容:
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity() {
$user = $auth->getIdentity();
echo $user->fullName; // Prints nothing...$_cdata['fullName'] does not exist.
}
有任何想法吗?