Controller:
function edit($id)
{
$this->form_validation->set_rules('name', 'Name', 'required|xss_clean');
$this->load->model('manager_model');
$pageData['type'] = 'managers';
$pageData['title'] = "Edit Manager";
$data['records'] = $this->manager_model->getManager($id);
$this->load->view('header', $pageData);
$this->load->view('db_options_view', $pageData);
if ($this->form_validation->run() == FALSE)
{
$this->load->view('managers/editManagerForm_view', $data);
}
else
{
$name = $this->input->post('name');
$this->manager_model->updateRecord($id, $name);
$this->load->view('managers/editManagerSuccess_view');
}
$this->load->view('footer');
}
Model:
function updateRecord($id, $name)
{
$data = array('name' => $name);
$this->db->where('id', $id);
$this->db->update('manager', $data);
}
My problem is this. My database table doesnt accept duplicate values for the name field. So while i was testing it i entered a duplicate name and codeigniter returned the following:
A Database Error Occurred
Error Number: 1062
Duplicate entry 'alan pardew' for key 2
UPDATE manager SET name = 'alan pardew' WHERE id = '2'
Filename: /var/www/vhosts/mysite.com/httpdocs/personal/models/manager_model.php
Line Number: 74
I would like to handle this error myself in the controller, and I have done a bit of reading up and found that I have to set $db['default']['db_debug'] = FALSE; to prevent codeigniter from displaying the errors.
Is there anyway of just turning particular errors off such as for duplicate entrys?
Or would you recommend switching them off completely?
Also..i'm fairly new to codeigniter so if you can spot any bad practice in my code feel free to point it out!