Created
November 23, 2015 21:04
-
-
Save bschwartz757/bb6cb0fdf13321cdb62d to your computer and use it in GitHub Desktop.
CodeIgniter News Controller for Annotation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//News.php | |
class News extends CI_Controller | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->load->model('news_model'); | |
$this->config->set_item('banner', 'News Banner'); | |
}//end constructor | |
public function index() | |
{ | |
$data['news'] = $this->news_model->get_news(); | |
$data['title'] = 'News archive'; | |
$this->load->view('news/index', $data); | |
}// end index | |
public function view($slug = NULL) | |
{ | |
$data['news_item'] = $this->news_model->get_news($slug); | |
if (empty($data['news_item'])) | |
{ | |
show_404(); | |
} | |
$data['title'] = $data['news_item']['title']; | |
$this->load->view('news/view', $data); | |
}//end view | |
public function create() | |
{ | |
$this->load->helper('form'); | |
$this->load->library('form_validation'); | |
$data['title'] = 'Create a news item'; | |
$this->form_validation->set_rules('title','Title','required'); | |
$this->form_validation->set_rules('text','text','required'); | |
if($this->form_validation->run() === FALSE) | |
{//data not submitted | |
$this->load->view('news/create', $data); | |
} | |
else | |
{//process data | |
$success = $this->news_model->set_news(); | |
if($success) | |
{ | |
$success = "News successfully entered!"; | |
}else | |
{ | |
$success = "News not entered!"; | |
} | |
$data['success'] = $success; | |
$this->load->view('news/feedback', $data); | |
} | |
}//end create function | |
}//end News |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment