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
)
)
)