分享一下findBy的应用案例
2014-03-25 18:07
267 查看
findBy<fieldName>(string $value);
将其作为findBy的神奇功能也接受一些可选参数:
findBy<fieldName>(string $value[, mixed $fields[, mixed $order]]);
findBy<x> Example Corresponding SQL Fragment $this->Product->findByOrderStatus('3'); Product.order_status = 3 $this->Recipe->findByType('Cookie'); Recipe.type = 'Cookie' $this->User->findByLastName('Anderson'); User.last_name = 'Anderson'; $this->User->findByEmailOrUsername('jhon', 'jhon'); User.email = 'jhon' OR User.username = 'jhon'; $this->User->findByUsernameAndPassword('jhon', '123'); User.username = 'jhon' AND User.password = '123'; $this->Cake->findById(7); Cake.id = 7
findBy()函数返回结果如发现('first')
Model::query()
query(string $query)
SQL调用,你不能或者不想让通过其他模型方法(这应该很少有必要)可以使用模型的query()方法。
如果你使用这个方法一定要正确转义所有参数使用value()方法在数据库驱动程序。未能逃脱参数将创建SQL注入漏洞。
query()使用查询中的表名数组键返回的数据,而不是模型的名字。例如:
$this->Picture->query("SELECT * FROM pictures LIMIT 2;");
可能返回:
Array
(
[0] => Array
(
[pictures] => Array
(
[id] => 1304
[user_id] => 759
)
)
[1] => Array
(
[pictures] => Array
(
[id] => 1305
[user_id] => 759
)
)
)
相关文章推荐
- java ----Applet两位整数运算(书上的案例 觉的挺好 发上来和大家分享一下)
- 电力行业工作流应用的成功案例分享
- Android原始应用与jquery mobile集成:案例分享
- Nginx应用案例分享:压力测试
- 分享10篇优秀的 jQuery 幻灯片制作教程及应用案例
- 商业智能(BI)案例分享之销售分析应用
- 分享17个微信创新应用案例 应用场景的不同应用
- Nginx应用案例分享:压力测试
- 分享20个Web开发中模式弹窗应用案例
- 一下视频:又一款社会化移动视频分享应用
- 分享20个Web开发中模式弹窗应用案例
- 分享30个应用HTML5的网站案例
- 分享一个基于ligerui的系统应用案例ligerRM V2(权限管理系统)(提供下载)
- 深入理解域之AD活动目录企业应用及案例分享
- 分享25个圆形元素在网页设计中的应用案例
- 分享一个基于ligerui的系统应用案例ligerRM V2(权限管理系统)(提供下载)
- 分享一个基于ligerui的系统应用案例ligerRM V2(权限管理系统)
- Nginx应用案例分享:压力测试
- 分享10篇优秀的jQuery幻灯片制作教程及应用案例
- [原创]Map应用___分享一下Map 排序