use*_*753 1 zend-framework2 tablegateway
我从ZendSkeletonApplication开始,添加了一个扩展Zend\Db\TableGateway\TableGateway的模型.我有以下方法:
public function findByType($type) {
$rowset = $this->select('type' => $type);
return $rowset;
}
Run Code Online (Sandbox Code Playgroud)
这有效,但现在如果我这样做:
$foo = $table->findBytype('foo');
$bar = $table->findBytype('bar');
Run Code Online (Sandbox Code Playgroud)
第一个工作,它执行的查询是:
SELECT * FROM table WHERE 'type' = 'foo'
Run Code Online (Sandbox Code Playgroud)
然而,第二个执行以下查询:
SELECT * FROM table WHERE 'type' = 'foo' AND 'type' = 'bar'
Run Code Online (Sandbox Code Playgroud)
这是预期的行为吗?如果是这样,我怎么能第二次调用该方法执行以下查询:
SELECT * FROM table WHERE 'type' = 'bar'
Run Code Online (Sandbox Code Playgroud)
提前致谢!
应该在tableGateway中选择如下:
$select = $this->getSql()->select();
$select->where(array('type' => 'foo'))
->where(array('type' => 'bar'));
$rowset = $this->selectWith($select);
Run Code Online (Sandbox Code Playgroud)
下次调用时,select()将重置where()参数.
在我的博客中查看更多用法:http: //avnpc.com/pages/advanced-database-select-usage-in-zf2
| 归档时间: |
|
| 查看次数: |
10813 次 |
| 最近记录: |