Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order by field in cakephp

I am doing project in cakephp .

I want to write below query in cakephp Style. I've written 50% . Please help me

$this->Login->find('all')

SELECT * FROM login  
ORDER BY FIELD(profile_type, 'Basic', 'Premium') DESC;
like image 377
Rinto George Avatar asked Mar 23 '12 09:03

Rinto George


4 Answers

Plese try this

$this->Login->find('all', array(
 'order'=>array('FIELD(Login.profile_type, "basic", "premium") DESC')
));
like image 142
benji Avatar answered Sep 22 '22 07:09

benji


You can pass options to the find method:

$this->Login->find('all', array(
  'order' => "FIELD(Login.profile_type, 'Basic', 'Premium') DESC"
));
like image 45
mensch Avatar answered Sep 25 '22 07:09

mensch


This one is more easy way to order and limit that works fine

$this->set('users', 
    $this->User->find('all', 
        array(
            'limit' => 3,
            'order' => 'User.created DESC'
       )
   )
);
like image 42
A.A Noman Avatar answered Sep 26 '22 07:09

A.A Noman


Please, try this:

$response = $this->Login->find('all', array('order'=>array('Login.profile_type'=>'desc')));
like image 20
LUIS TOBIO GUTIERREZ Avatar answered Sep 24 '22 07:09

LUIS TOBIO GUTIERREZ