2012-03-23 10 views
16

Estoy haciendo un proyecto en cakephp.Ordenar por campo en cakephp

Quiero escribir debajo de la consulta en cakephp Style. He escrito 50%. Por favor me ayude a

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

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

Respuesta

20

Intente a introducir este

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

Usted puede pasar opciones a the find method:

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

Por favor, intente esto:

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

Ésta es la forma más fácil de ordenar y límite que funciona bien

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