How would you (elegantly) order a select statement by a field using closures in Zend Framework 2?
I have the following PHP code:
$gateway = new \Zend\Db\TableGateway\TableGateway('table_name', $adapter);
$select = $gateway->select(function($select){
$select->where->in('id', array(4, 2, 3, 1));
// insert some awesome ordering magic here..!
});
I'm aware that you could easily do this:
...
$select->order(array('id ASC'));
...
But that would just order the results by ascending id
value, and I need to order them by a specific id sequence (i.e.: have them ordered in the sequence 4, 2, 3, 1
.
Is there an elegant Zend Framework 2 function I could use here to order by the id
's themselves? Effectively creating the SQL:
select * from table_name
where 'id' in (4, 2, 3, 1)
order by field('id', (4, 2, 3, 1));