Answer the question
In order to leave comments, you need to log in
How to catch an error when deleting a model?
There is an entry in the table that they are trying to delete. It could be referenced from other tables, respectively, in this case, you need to display a message about the impossibility of deletion.
How to check if a post can't be deleted?
try {
$model->delete();
} catch (Exception $e) {
}
Such code catches this exception from a DB, the script falls down with an error.
How to catch an exception, or is there something like the canDelete() method in Yii2 to check if the deletion is possible?
I do not want to manually check if there are links to this record in other tables.
Answer the question
In order to leave comments, you need to log in
Suddenly needed.
www.yiiframework.com/doc-2.0/yii-db-integrityexcep...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question