Hi,
Otherwise you can do this for example:
$select = $this->select(
function (Select $select) use ($userEmail, $userId) {
$select->where->equalTo('email', $userEmail);
if ($userId !== null) {
$select->where->notEqualTo('id', $userId);
}
}
);
2013/9/15 András Csányi <[email protected]>
> I got this as an answer, I hope it may help for others.
>
> Hello Andras,
>
> Just saw you message....
> Didn't want to clutter the list with the reply...
>
> Simply there is addPredicate internal mechanism used in those classes....
> You've got to pass a filter to select closure then apply it in the
> closure body...
>
> Try this:
> $filter = new Zend\Db\Sql\Predicate\Predicate();
> $filter->equalTo('fielda',5)->and->lessThan('fieldb',4);
> $limit = 1000;
> $orderseq = array('name'=>'DESC','number'=>'ASC');
> $this->tableGateaway->select(function(Select $select) use
> ($filter,$limit,$orderseq){
> $select->where($filter);
> $select->limit($limit);
> $select->order($orderseq);
> });
>
> More details here:
>
> https://github.com/zendframework/zf2/blob/master/library/Zend/Db/Sql/Predicate/Predicate.php
>
> It's quite obvious how it is realized in ZF2:
>
> https://github.com/zendframework/zf2/blob/master/library/Zend/Db/TableGateway/AbstractTableGateway.php
> (skip down to select() function signature).
>
> Any questions - will be happy to help...
>
> Best regards, Konstantin
>
> Best regards,
> Konstantin
>
> On 14 September 2013 19:40, András Csányi <[email protected]> wrote:
> > Hi All,
> >
> > I implemented the TableGateway pattern based-on the tutorial, but I
> > don't know how to select data from the database when the where is
> > complicated. I went through the reference but I did not found anything
> > useful. On the other hand, I did not find any help in the
> > documentation about how is possible to use Select and Sql objects, If
> > I recall correctly then in ZF1 it was possible to use these object to
> > put together the query.
> >
> > So, I would like to execute a query which looks like this:
> >
> > "SELECT column1, column2, column3 FROM table WHERE column_z like
> > '%string%' AND column_f like '%string2%'"
> >
> > The point of the whole is that there are multiple where conditions.
> >
> > If you know a blog where it is described or an article somewhere I
> > would be very happy!
> >
> > Thanks for any help in advance!
> >
> > András
> >
> > --
> > -- Csanyi Andras (Sayusi Ando) -- http://sayusi.hu --
> > http://facebook.com/andras.csanyi
> > -- ""Trust in God and keep your gunpowder dry!" - Cromwell
>
>
>
> --
> -- Csanyi Andras (Sayusi Ando) -- http://sayusi.hu --
> http://facebook.com/andras.csanyi
> -- ""Trust in God and keep your gunpowder dry!" - Cromwell
>
> --
> List: [email protected]
> Info: http://framework.zend.com/archives
> Unsubscribe: [email protected]
>
>
>
--
Pierre Rambaud
Website: http://pierrerambaud.com <http://rambaudpierre.fr>
G+: https://plus.google.com/u/0/107809758756474139920/posts
Github: https://github.com/PierreRambaud