$slug = str_replace(' ', '-', $this->input->post('title'));
$slug = strtolower($slug);
$subject_name = str_replace(' ', '-', $this->input->post('subject_name'));
$subject_name = strtolower($subject_name);
// Upload Image
$config['upload_path'] = 'assets/img/posts/';
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$file_name = 'post_image';
if(!$this->upload->do_upload($file_name)){
varDebug($this->upload->display_errors());
$file_name = base_url().'assets/img/noimage.jpg';
} else {
$data = array('upload_data' => $this->upload->data($file_name));
}
// Page Data
$data = array(
'subject_id' => $this->input->post('subject_id'),
'subject_name' => $subject_name,
'user_id' => $this->input->post('user_id'),
'username' => $this->input->post('username'),
'slug' => $slug,
'title' => $this->input->post('title'),
'post_image' => $file_name,
'body' => $this->input->post('body'),
'is_published' => $this->input->post('is_published'),
'is_featured' => $this->input->post('is_featured'),
'in_menu' => $this->input->post('in_menu'),
'is_commented' => $this->input->post('is_commented'),
'order' => $this->input->post('order'),
);
// Insert Page
$this->Post_model->add($data);