我有一个从mysql抓取数据的元素。以下是我的工作代码:
$this->requestAction('posts/index/sort:id/direction:desc');我只想抓取id1和id6之间的帖子。如何通过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天)
发布于 2010-07-05 21:09:35
如果我要通过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
另外,别忘了,如果您编写requestAction方法,检查$this->params['requested']是否为真,这样您就知道它来自requestAction
https://stackoverflow.com/questions/3179644
复制相似问题