【发布时间】:2013-07-02 13:30:49
【问题描述】:
我正在开发一个 cakephp 2.x。想在我的保存查询中添加一个条件。例如,我想实现这个查询
INSERT INTO 'this' where condition is 'this'
我现在正在这样做
$count = $this->Message->find('count', array(
'conditions' => array('Message.mobileNo' => $mobileNo,
'Message.body'=>$body
)));
if($count>0){
echo "already have a message";
}else
{
$this->Message->create();
$this->Message->save($this->request->data);
}
现在我有时首先检查计数,然后保存到数据库中...我可以在我的 save 中添加条件,这样我就不必为了完成一项任务而查询两次数据库
【问题讨论】:
-
为什么不在模型中为此使用自定义验证规则?会更干净:book.cakephp.org/2.0/en/models/…
标签: cakephp cakephp-2.0 cakephp-2.1