CakePHP如何通过ID的数组获取多行 [英] CakePHP how to get multiple rows by array of ID's

查看:154
本文介绍了CakePHP如何通过ID的数组获取多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据库中提取多行,根据数组的ID列表。



在其他一些框架中似乎有一些像WHERE_IN,但不是在这里。



有人能告诉我该怎么办吗?



我想知道如何通过find()或read()(或任何其他cakephp函数),并且不手动构建查询,因为我想

谢谢

解决方案

根据复杂查找功能(第三个示例)这应该工作:

  $ this-> YourModel-> find('all',array 
'conditions'=> array(
YourModel.id=> array(1,2,3,4)



I would like to pull from database multiple rows, according to a list of array of ID's.

In some other frameworks there seem to be something like "WHERE_IN", but not here.

Can someone tell me how to do it?

I would like to know how to do that through the find() or read() (or any other cakephp function) and NOT build a query manually, since I want all data to be escaped and secure.

thank you

解决方案

According to "Complex Find Functions" (third example) this should work:

$this->YourModel->find('all', array(
    'conditions' => array(
        "YourModel.id" => array(1, 2, 3, 4)
    )
));

这篇关于CakePHP如何通过ID的数组获取多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆