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

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

问题描述

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

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

在其他一些框架中似乎有WHERE_IN"之类的东西,但在这里没有.

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

谁能告诉我怎么做?

我想知道如何通过 find() 或 read()(或任何其他 cakephp 函数)来做到这一点,而不是手动构建查询,因为我希望所有数据都经过转义和保护.

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.

谢谢

推荐答案

根据 "Complex Find Functions" (第三个例子) 这应该工作:

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天全站免登陆