我試圖找出如果我的$任命實體爲空或不在CakePHP的空白,但這並不工作:檢查的實體是一個在CakePHP 3
$appointment = $this->Appointments->get($id);
if($appointment->isEmpty()) {
throw new NotFoundException("invalid appointment");
}
錯誤:
Error: Call to undefined method App\Model\Entity\Appointment::isEmpty()
這樣做的正確方法是什麼? docs說它適用於Query
或ResultSet
,但我需要它提供的代碼。
或者只是使用find()來代替,如果可以通過設計阻止這種錯誤,請不要嘗試捕獲該錯誤。 – mark