0

In Zendframework 1 we use the following code in the models to apply where and order by clauses:

$this->select()
     ->where('WHERE CLAUSE')
     ->order('ORDER FIELDS');

But in Zendframework 2 it has been changed to:

$this->select('WHERE CLAUSE');

I dont know how to apply order by clause to my select object.

rahim asgari
  • 12,197
  • 10
  • 43
  • 53

1 Answers1

0

There are actually several ways to achieve where-clauses in ZF2, the most 'nerdy' one being

$select = $this->select();

$where = function(Where $clause) {
  $clause->like('username', 'foo%');
};

$select->where($where);

As for the orther, it's the same as in ZF1

$select->order('id DESC');

Read more about the possibilities inside the Official Documentation of \Zend\Db\Sql

Sam
  • 16,435
  • 6
  • 55
  • 89