Inside a controller I want to make an insert into the database :
public function insertAction() {
try {
$this->load->model('action');
$_POST['laDate'] = $this->input->post('ladate_') == '' ? '' : $this->dates->convertDateToFormatBase($this->input->post('ladate_'), '');
$_POST['dateCreation'] = "now()";
$action_id = $this->action->ajouter($_POST);
if (isset($_POST['verificateurs'])) {
$this->load->model('actionVerificateur');
$this->actionVerificateur->inserer($action_id, $_POST['verificateurs']);
}
$this->load->view('ajax/insertAction', array('action_id' => $action_id));
}
catch (Exception $e) {
$this->load->view('ajax/insertAction', array('action_id' => 0));
}
}
There is a unique constraint on some columns of the database table. So when this constraint is violated then I want to catch the exception. But it seems that my code does not catch it ! So how to catch the exception ?
Transactions. I never heard of using TRY CATCH in the framework. Cz Framework helps thing easy. But you doing old still