2012-04-24 77 views
1

我開始使用ZendSkeletonApplication並添加了一個擴展Zend \ Db \ TableGateway \ TableGateway的模型。 我有以下方法:ZF2 tableGateway select

public function findByType($type) { 
    $rowset = $this->select('type' => $type); 
    return $rowset; 
} 

這工作,但現在如果我這樣做:

$foo = $table->findBytype('foo'); 
$bar = $table->findBytype('bar'); 

的第一個作品,它執行的查詢是:

SELECT * FROM table WHERE 'type' = 'foo' 

的然而第二個執行以下查詢:

SELECT * FROM table WHERE 'type' = 'foo' AND 'type' = 'bar' 

是這種預期的行爲? 如果是的話我怎麼會有我第二次調用該方法執行以下查詢:

SELECT * FROM table WHERE 'type' = 'bar' 

在此先感謝!

+0

原來這只是在已經媒體鏈接被固定在最新的github版本ZF2素β3一個小錯誤。 – user458753 2012-04-25 07:43:36

回答

8

應在tableGateway使用選擇這樣的:

$select = $this->getSql()->select(); 
$select->where(array('type' => 'foo')) 
    ->where(array('type' => 'bar')); 
$rowset = $this->selectWith($select); 

選擇()將重置,其中()paramters當你把它下一次。

見我的博客更多的使用: http://avnpc.com/pages/advanced-database-select-usage-in-zf2

+0

您的博客是否有英文版本?片段做得很好,但我用中文獲取了所有內容,Google試圖用德語翻譯它,這是一種有趣的體驗;-) – 2017-07-28 10:06:29