2012-03-23 14 views
16

Sto facendo un progetto in cakephp.Ordina per campo in cakephp

Voglio scrivere sotto query in stile cakephp. Ho scritto il 50%. Please help me

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

SELECT * FROM login 
ORDER BY FIELD(profile_type, 'Basic', 'Premium') DESC; 

risposta

20

Plese provare questo

$this->Login->find('all', array(
 'order'=>array('FIELD(Login.profile_type, "basic", "premium") DESC') 
)); 
3

È possibile passare opzioni a the find method:

$this->Login->find('all', array(
    'order' => "FIELD(Login.profile_type, 'Basic', 'Premium') DESC" 
)); 
1

Per favore, prova questo:

$response = $this->Login->find('all', array('order'=>array('Login.profile_type'=>'desc'))); 
1

Questo è il modo più semplice per ordinare e limite che funziona bene

$this->set('users', 
    $this->User->find('all', 
     array(
      'limit' => 3, 
      'order' => 'User.created DESC', 
      'recursive' => 1, 
     ) 
    ) 
);