2012-03-23 46 views
16

我在cakephp中做項目。在cakephp中按字段排序

我想在cakephp Style中寫下面的查詢。我寫了50%。請幫我

$這個 - >登錄 - >找到( '全部')

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

回答

20

普萊舍試試這個

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

你可以通過選項來the find method

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

請試試這個:

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

這一個是下令正常工作更簡單的方法,並限制

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