Skip to content

Instantly share code, notes, and snippets.

@bschwartz757
Created November 23, 2015 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bschwartz757/bb6cb0fdf13321cdb62d to your computer and use it in GitHub Desktop.
Save bschwartz757/bb6cb0fdf13321cdb62d to your computer and use it in GitHub Desktop.
CodeIgniter News Controller for Annotation
<?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