контроллер:
Код: Выделить всё
public function update_contact()
{
sleep(1);
$data['validation_error'] = '';
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|max_length[40]|callback_alpha_dash_space');
$this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
$this->form_validation->set_rules('phone', 'Phone', 'required|max_length[15]|alpha_numeric');
$this->form_validation->set_rules('cbo_list', 'Group Name', 'required');
if ($this->form_validation->run() == false) {
$message = "[b]Editing[/b] failed!";
$this->json_response(false, $message);
} else {
$this->contact_model->update(
$this->input->post('name'),
$this->input->post('email'),
$this->input->post('phone'),
$this->input->post('cbo_list'),
$this->session->userdata('uid')
);
$message = "[b]" . $this->input->post('name') . "[/b] has been edited!";
$this->json_response(true, $message);
redirect("site/contacts");
}
}
Код: Выделить всё
public function update($cid, $name, $email, $phone, $cbo_list)
{
$this->db->where(array(
'uid' => $this->session->userdata('uid'),
'cid' => $cid
))
->update('contacts', array(
'name' => $name,
'email' => $email,
'phone' => $phone,
'gid' => $cbo_list
));
}
- имя моего контакта = сайт,
- имя моей модели = контактная_модель,
- моя таблица = контакты и группа_контакты, где контакты.гид = group_contacts.gid
Если я запущу его, ошибок не будет, но я не смогу изменить данные.
Подробнее здесь: https://stackoverflow.com/questions/232 ... e-database