0

我有一个从 mysql 获取数据的元素。这是我的工作代码:

$this->requestAction('posts/index/sort:id/direction:desc');

我只想抓取 id 1 和 6 之间的帖子。如何通过 requestAction 运行该查询?我尝试过的一些脚本如下。没有工作:

$this->requestAction('posts/index/sort:id/direction:desc', array('id between ? and ?' => array('1,6')));

或者

$this->requestAction('posts/index/sort:id/between:1,6/direction:desc');

您可以在http://bake.yemeklog.com/上看到我的项目我想要此代码用于第三列(过去 30 天的最爱)

4

1 回答 1

0

如果我要通过requestAction(!) 调用它,那么我会在我的控制器中编写一个自定义方法,然后我可能会将两个 id 作为参数传递给该方法。

然后您可以处理参数并制定您的查询。

$this->Model->find('all', 'conditions' => array('id'=>array(1,2,3,4,5,6)));

无论如何都不理想,但我不太确定我还能如何解决这类问题。

如果它是静态ID,那么也许

$this->Model->find('all', null, null, 'order' => 'id ASC LIMIT 0,6');

** 现在我不确定这是否可行,因为我还没有尝试过,但我经常将这样的小东西破解到 Cake 中并取得了一些成功。所以也许试一试,一定要设置debug = 2这样你就可以看到查询,或者从 OhLo 获取 DebugKit

PS,不要忘记如果您编写 requestAction 方法,请检查$this->params['requested']是否属实,因此您知道它来自 requestAction

于 2010-07-05T13:09:35.210 回答