1

I started with the ZendSkeletonApplication and added a model extending Zend\Db\TableGateway\TableGateway. I have the following method:

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

This works, but now if i do this:

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

the first one works, the query it executes is:

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

The second one however executes the following query:

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

is this expected behavior? If so how can i have the second time i call the method execute the following query:

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

thanks in advance!

4

1 回答 1

8

应该像这样在 tableGateway 中使用 select:

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

select() 将在您下次调用时重置 where() 参数。

在我的博客中查看更多用法:http: //avnpc.com/pages/advanced-database-select-usage-in-zf2

于 2012-06-09T08:08:16.367 回答