2010-06-23 40 views
0

我有一個擴展Zend_Db_Table_Abstract類內部時,下面的代碼:改變Zend_Db_Select對象的輸出Zend_Db_Table_Rowset

public function fetchByFriends($id) { 
    /* 
    * SELECT * FROM list 
    * INNER JOIN friendship ON 
    * list.user_id = friendship.friend_id 
    * WHERE friendship.user_id = ? 
    */ 

    $select = $this->select() 
        ->from("list") 
        ->join("friendship", "list.user_id = friendship.friend_id") 
        ->where("friendship.user_id = ?", $id); 
    $select->setIntegrityCheck(false); // allows joins within a DbTable 

    $stmt = $select->query(); 
    return $this->fetchAll($stmt); 
} 

雖然查詢工作正常返回的數據是一個數組的。有沒有什麼方法來重構這個,以便fetchAll將它作爲Zend_Db_Table_Rowset返回,而不是數組?

回答

0

我的研究很差。我發現在Zend的參考手冊的答案:

Advanced usage

實施例#27使用查找表來細化使用fetchall的)的結果(

$table = new Bugs(); 

// retrieve with from part set, important when joining 
$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART); 
$select->setIntegrityCheck(false) 
     ->where('bug_status = ?', 'NEW') 
     ->join('accounts', 'accounts.account_name = 

bugs.reported_by」 ) - > where('accounts.account_name =?','Bob');

$rows = $table->fetchAll($select);