打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
CakePHP 获取数据find() list 和 neighbors
如果使用find('list')进行查找,$params中的'fields'的值有所不同,这个时候定义的是结果集的索引(key),值(value)和组(group):

1
// 生成由Post.id索引的,值为Post.title的list。
2
$this->Post->find('list', array('fields'=>'Post.title'));
3
 
4
// 生成由Post.slug索引的,值为Post.title的list。
5
$this->Post->find('list', array('fields'=>array('Post.slug', 'Post.title')));
6
 
7
// 生成的list将按照Post.author_id进行分组,然后由Post.id进行索引,值为Post.title
8
$this->Post->find('list', array('fields'=>array('Post.id', 'Post.title', 'Post.author_id')));
9


如果使用find('neighbors')进行查找,$params中的'field'表示用来分析的字段,'value'则用来定义查找相邻数据(neighbor)时使用的值。注意'field''value'只在find('neighbors')时有效,在find('all’)中是不使用的。

1
// 比如有1-10的id,想要取得上一个(1)和下一个(3)的数据。
2
$this->Post->id = 2;
3
$one = $this->Post->find('neighbors');
4
// 使用不同的字段查找相邻数据。
5
$two = $this->Post->find('neighbors', array('field'=>'Post.title', 'value'=>$data['Post']['title']));
6

 为了提供对以前版本的兼容,find也可以接收下面的参数形式:

find(string $conditions, array $fields, string $order, int $recursive) 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
mongodb返回刚插入数据的id用什么方法
play framework学习笔记之模型域model
WordPress文章内容底部添加相关文章
WordPress无插件调用最新、热门、随机文章实例代码【wordpress随机文章】
YII AR
448. Find All Numbers Disappeared in an Array
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服