Skip to content

Commit

Permalink
modified controller news
Browse files Browse the repository at this point in the history
  • Loading branch information
Risyandi committed May 6, 2019
1 parent ee25130 commit d6209cc
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions source-apps/controllers/News.php
Expand Up @@ -9,16 +9,22 @@ public function __construct(){
$this->load->helper('url_helper');
}

/**
* method index view
*/
public function index(){
$data['news'] = $this->news_models->get_news();
$data['news'] = $this->news_models->getNews();
$data['title'] = 'Listing News';
$this->load->view('components/header', $data);
$this->load->view('news/index', $data);
$this->load->view('components/footer', $data);
}

/**
* method read
*/
public function view($slug = NULL){
$data['news_item'] = $this->news_models->get_news($slug);
$data['news_item'] = $this->news_models->getNews($slug);
if (empty($data['news_item'])) {
show_404();
}
Expand All @@ -29,25 +35,41 @@ public function view($slug = NULL){
$this->load->view('components/footer', $data);
}

/**
* method create
*/
public function create() {
$this->load->helper('form');
$this->load->library('form_validation');

$data['title'] = 'Create News';

$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');

if ($this->form_validation->run() === FALSE) {
$this->load->view('components/header', $data);
$this->load->view('news/create');
$this->load->view('components/footer');
} else {
$this->news_models->setNews();
$this->load->view('components/header', $data);
$this->load->view('news/success');
$this->load->view('components/footer');
}
}

/**
* method delete
*/
public function delete($id=null){
if(!isset($id)){
show_404();
}

if ($this->form_validation->run() === FALSE) {
$this->load->view('components/header', $data);
$this->load->view('news/create');
$this->load->view('components/footer');
} else {
$this->news_models->set_news();
$this->load->view('components/header', $data);
$this->load->view('news/success');
$this->load->view('components/footer');
if($this->news_models->deleteNews($id)){
redirect(site_url('/news'));
}
}
}

}

0 comments on commit d6209cc

Please sign in to comment.