public function add()
 {
     if ($this->input->post()) {
         $this->form_validation->set_rules('category', 'Category Name', 'required');
         if ($this->form_validation->run() == FALSE) {
             $this->data['form'] = array('category' => $this->input->post('category'));
             $this->data['errors'] = '';
             $this->load->view('admin/add-category', $this->data);
         } else {
             $categoryObj = new categories_model();
             $categoryObj->name = $this->input->post('category');
             $categoryObj->status = 0;
             $categoryObj->image = 'defaults.jpg';
             $categoryObj->insert();
             if (!$categoryObj->id) {
                 echo "Fail";
             } else {
                 if (isset($_FILES['image']) && is_uploaded_file($_FILES['image']['tmp_name'])) {
                     $this->data['form'] = $categoryObj->get();
                     // File Uploading
                     $config['upload_path'] = './assests/categories/';
                     $config['allowed_types'] = 'gif|jpg|png';
                     $config['max_size'] = '100';
                     $config['max_width'] = '1024';
                     $config['max_height'] = '768';
                     $config['file_name'] = 'category_' . $categoryObj->id;
                     $this->load->library('upload', $config);
                     if (!$this->upload->do_upload('image')) {
                         $this->session->set_flashdata('error', $this->upload->display_errors());
                         redirect('admin/category/edit/' . $categoryObj->id, 'refresh');
                     } else {
                         $data = array('upload_data' => $this->upload->data());
                         $categoryObj->image = $data['upload_data']['file_name'];
                         $categoryObj->update();
                     }
                 }
                 redirect('admin/category', 'refresh');
             }
         }
     } else {
         $this->data['form'] = '';
         $this->data['errors'] = '';
         $this->load->view('admin/add-category', $this->data);
     }
 }