通常,您只需在 DbTable 模型或映射器类中添加一个方法来为您获取此数据。对于您当前的问题,请尝试以下操作:
$usersTable = new Application_Model_DbTable_Users();
$zendSession = new Zend_Session_Namespace();
$select = $usersTable->select();
$select->from($usersTable,array('id', 'first_name', 'last_name', 'email', 'status'))
->where("id = ?", $userInsertQuery);
$zendSession->userData = $usersTable->fetchRow($select);
Zend_Db_Select 似乎认为您试图访问多个表,因为您使用了两种不同的方法(将对象作为表名传递,将字符串作为表名传递)在同一个查询中访问同一个表。
DbTable 中的方法可能如下所示:
public function getUserData($id)
{
$select = $this->select();
$select->from($this, array('id', 'first_name', 'last_name', 'email', 'status'));
$select->where('id = ?', $id);
$result = $this->fetchRow($select);
return $result;
}
然后在你的控制器中:
$usersTable = new Application_Model_DbTable_Users();
$user = $usersTable->getUserData($userInsertQuery);
$zendSession->userData = $user;
毕竟,您可以使用 Zend_Auth_Storage_Session 存储您想要的信息,有点像:
if ($result->isValid()) {
//store the username, first and last names of the user
$auth = Zend_Auth::getInstance();
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(array(
'username', 'first_name', 'last_name'
)));
//or to save all except
$storage->write($authAdapter->getResultRowObject(null, array('password', 'salt'));
}
然后稍后您可以通过调用调用该信息:
$auth = Zend_Auth::getInstance();
$storage = $auth->getStorage();
$strorage->read();
或者您可以使用 Zend_Auth 命名空间直接从 Zend_Session_Namespace 访问相同的信息:
$session = new Zend_Session_Namespace('Zend_Auth');
$member = $session->storage; //'storage' is the default. However the namespace and key can be changed.