有没有办法检查蛋糕php中是否存在记录.我知道有一个功能.CakePHP 2
$this->Notes->id = $id;
if (!$this->Notes->exists())
{
throw new NotFoundException(__('Invalid Notes'));
}
Run Code Online (Sandbox Code Playgroud)
但默认情况下,它会检查列id如何检查自定义列,假设它是note_id.我的attemts是从这里引用的
尝试#1
if (!$this->Noteshistory->exists(['note_id'=>$id]))
{
throw new NotFoundException(__("Invalid Note "));
}
Run Code Online (Sandbox Code Playgroud)
还尝试设置note_id
$this->Noteshistory->note_id = $id;
if (!$this->Noteshistory->exists(['note_id'=>$id]))
{
throw new NotFoundException(__("Invalid Note "));
}
Run Code Online (Sandbox Code Playgroud)
但没有运气.
Sou*_*ose 12
hasAny是解决方案 -
$this->Noteshistory->hasAny(['note_id'=>$id])
Run Code Online (Sandbox Code Playgroud)
true如果找到别的话会返回false
hasAny在3.x版本中不可用