Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*=================================================================================
- ADD ARTICLE
- ==================================================================================*/
- public function add(){
- $this->load->helper('application_helper');
- //Validation Rules
- $this->form_validation->set_rules('title','title','required');
- $this->form_validation->set_rules('body','Body','trim|required');
- $this->form_validation->set_rules('is_published','Publish','required');
- $this->form_validation->set_rules('category','Category','required');
- $data['categories'] = $this->Article_model->get_categories();
- $data['users'] = $this->User_model->get_users();
- $data['groups'] = $this->User_model->get_groups();
- if( $this->form_validation->run() == FALSE ){
- // if the form has not been submitted, show the add article form
- $data['main_content'] = 'admin/articles/add'; // the form
- $this->load->view('admin/layouts/main', $data); // template that contains this form
- }
- else { // Collect the values when the form is submitted
- // POST FEATURED IMAGE DATA
- $config['upload_path'] = './uploads/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '1000';
- $config['max_width'] = '1300';
- $config['max_height'] = '1300';
- $this->load->library('upload', $config);
- // Check
- if( !$this->upload->do_upload('post_image') ) {
- //echo $this->upload->display_errors() ;
- echo '<br><h1>IMAGE COULD NOT BE UPLOADED</h1><br>';
- //exit() ;
- $image = '';
- }
- else {
- $data_upload_files = $this->upload->data();
- echo '<h1>IMAGE WAS SUCCESSFULLY UPLOADED CHECK DATABASE</h1>';
- $image = $data_upload_files['file_name'];
- echo 'The name of the file is: ' . $image ;
- }
- // Check if the seoUrl helper was successful
- $seo_url = seoUrl( $this->input->post('slug') ) ;
- if ( empty( $seo_url ) ) {
- $seo_url = seoUrl( $this->input->post('title') ) ;
- }
- //Create Articles Data Array
- $data = array(
- 'title' => $this->input->post('title'),
- 'body' => $this->input->post('body'),
- 'slug' => $seo_url,
- 'post_image' => $image,
- 'category_id' => $this->input->post('category'),
- 'user_id' => $this->input->post('user'),
- 'access' => $this->input->post('access'),
- 'is_published' => $this->input->post('is_published'),
- 'in_menu' => $this->input->post('in_menu'),
- 'order' => $this->input->post('order')
- );
- echo "<br><br>the name of this Image FIle is: $image <br><br>" ;
- // Insert to Articles table, this is defined on the model
- //print_r($data) ;
- //exit() ;
- $this->Article_model->insert($data);
- print_r($data) ;
- exit() ;
- //Create Message
- $this->session->set_flashdata('article_saved', 'Your article has been saved');
- //Redirect to pages
- redirect('admin/articles');
- }
- }
- /*=================================================================================
- EDIT ARTICLE
- ==================================================================================*/
- public function edit($id){
- //Validation Rules
- $this->form_validation->set_rules('title','Title');
- $this->form_validation->set_rules('body','Body','trim|required');
- $this->form_validation->set_rules('is_published','Publish','required');
- $this->form_validation->set_rules('category','Category','required');
- $data['categories'] = $this->Article_model->get_categories();
- $data['users'] = $this->User_model->get_users();
- $data['article'] = $this->Article_model->get_article($id);
- $data['groups'] = $this->User_model->get_groups();
- if ($this->form_validation->run() == FALSE){
- //Views
- $data['main_content'] = 'admin/articles/edit';
- $this->load->view('admin/layouts/main', $data);
- }
- else {
- // POST FEATURED IMAGE DATA
- $config['upload_path'] = './uploads/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '1300';
- $config['max_width'] = '1300';
- $config['max_height'] = '1300';
- $this->load->library('upload', $config);
- echo 'after load library upload';
- if( ! $this->upload->do_upload('post_image') ) {
- echo $this->upload->display_errors() ;
- echo '<br><h1>IMAGE COULD NOT BE UPLOADED</h1><br>';
- $image = '';
- }
- else {
- $this->upload->do_upload();
- $data_upload_files = array('upload_data' => $this->upload->data() );
- $image_data = $this->upload->data() ;
- echo 'Data Upload Files: ' . print_r($data_upload_files) . ' <br>' ;
- echo '<h1>IMAGE WAS SUCCESSFULLY UPLOADED CHECK DATABASE</h1>';
- $image = $image_data['file_name'];
- }
- //Create Articles Data Array
- $data = array(
- 'title' => $this->input->post('title'),
- 'body' => $this->input->post('body'),
- 'slug' => $this->input->post('slug'),
- 'post_image' => $image,
- 'category_id' => $this->input->post('category'),
- 'user_id' => $this->input->post('user'),
- 'access' => $this->input->post('access'),
- 'is_published' => $this->input->post('is_published'),
- 'in_menu' => $this->input->post('in_menu'),
- 'order' => $this->input->post('order')
- );
- //Articles Table Insert
- $this->Article_model->update($data, $id);
- //Create Message
- $this->session->set_flashdata('article_saved', 'Your article has been saved');
- //Redirect to pages
- redirect('admin/articles');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement