use Cake\Core\Exception\Exception;
for($i=1; $i<count($values); $i++) {
$entity = $table->newEntity();
try {
$table->save($entity);
} catch (Exception $e) {
$errors[$i-1] = $values[$i];
} finally {
if(count($errors) == 0)
$this->Flash->success('All rows are successfully imported. ');
else {
$this->Flash->error('Not all rows are successfully imported. ');
debug($errors);
}
}
}
What I want to do is to catch conflicting objects and show them to the user.
I get a PDO exception. Those that do not conflict are still inserted what I want.
So I just want to catch the PDO exception, but how?
source
share