Simple question:
How to set GoneExceptions when using Table::get($id)?
We now use like:
$post = $this->Posts->find()
->where(['Posts.id' => $id])
->first();
if (!$post) {
throw new GoneException('Custom error message');
}
But how to use with $this->Posts->get($id);
Books says:
If the get operation does not find any results a
Cake\Datasource\Exception\RecordNotFoundException
will be raised. You can either catch this exception yourself, or allow CakePHP to convert it into a 404 error.
scrutinizer report bug:
Accessing
contact_idon the interface
Cake\Datasource\EntityInterfacesuggest that you code against a concrete implementation. How about adding an
instanceofcheck?