php 按 cakephp 中的字段排序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9836704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:44:39  来源:igfitidea点击:

Order by field in cakephp

phpcakephpsql-order-by

提问by Rinto George

I am doing project in cakephp .

我在 cakephp 做项目。

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

我想在 cakephp 样式中编写以下查询。我已经写了 50% 。请帮我

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

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

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

回答by benji

Plese try this

请试试这个

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

回答by mensch

You can pass options to the findmethod:

你可以通过选项find方法

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

回答by LUIS TOBIO GUTIERREZ

Please, try this:

请试试这个:

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

回答by A.A Noman

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',
            'recursive' => 1,
       )
   )
);