通常你只是在你的DBTABLE模型或映射器類添加一個方法來爲你獲取這些數據從DB獲得一定的列名。對於當前的問題,試試這個:
$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_Session_Namespace使用Zend_Auth的命名空間直接訪問相同的信息:
$session = new Zend_Session_Namespace('Zend_Auth');
$member = $session->storage; //'storage' is the default. However the namespace and key can be changed.