#php #codeigniter #backend
Вопрос:
Я совсем новичок в codeigniter, и у меня есть проект, над которым я работаю, в котором мне нужно создать страницу редактирования для загрузки.
Вот что я попробовал, это модель страницы.
public function update_cat($name, $cat_slug, $new_slug, $description){
$upload_cat_id = $this->get_where($cat_slug);
foreach ($upload_cat_id as $c_id):
$id = $c_id->upload_cat_id;
endforeach;
$update_upload_cat = "UPDATE `upload_category` SET `name`= '". $name ."',`cat_slug`='". $new_slug ."',`description`='". $description ."' WHERE upload_cat_id = '". $id ."'";
$this->db->trans_start();
$this->db->query($update_upload_cat);
$this->db->trans_complete();
if($this->db->trans_status() === FALSE){
$error = $this->db->error(); // Has keys 'code' and 'message'
return $error;
} else {
return TRUE;
}
}
а вот и контроллер
public function edit($slug){
$data['alert'] = $this->alert;
$data['error'] = '';
//Set Rules From validation
$this->form_validation->set_rules('edit_name', 'Category Name', 'required');
if($this->form_validation->run() === FALSE){
$data['title'] = $this->site_info;
$data['page_title'] = 'Update Upload Category';
$data['category'] = $this->upload_cat_model->get_where($slug);
$view_name = 'backendview/edit_upload_cat_view';
$this->load_view($view_name, $data);
} else {
$name = $this->input->post('edit_name');
$new_slug = url_title($this->input->post('edit_name'), 'dash', TRUE);
$description = $this->input->post('description');
$update_upload_cat = $this->upload_cat_model->update_cat($name, $slug, $new_slug, $description);
if($update_upload_cat == TRUE){
$this->alert = ' <div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">amp;times;</button>
<h4><i class="icon fa fa-check"></i> Successful!</h4>
The category was successfully Updated.
</div>';
$this->index();
} else {
$this->alert = '<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">amp;times;</button>
<h4><i class="icon fa fa-ban"></i> Unsuccessful!</h4>
An error occurred while we were trying to update the category. Hence, the category was NOT successfully Updated.
</div>';
$this->index();
}
}
}