controller (application/controllers/roll_c.php):
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class roll_c extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->library('grocery_CRUD');
$this->load->library('session');
}
public function index()
{
$this->rolls();
}
public function rolls()
{
$crud = new grocery_CRUD();
if($this->session->userdata('logged_in')) //if not logged in, disable editing
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
}
else
{
$crud->unset_delete();
$crud->unset_edit();
$crud->unset_add();
$data['username'] = '';
//TODO:add detailed view
}
$crud->columns('Roll_Name','Link','Description', 'ArtworkStyleID', 'DateStart', 'DateEnd', 'Country');
$crud->fields('Roll_Name','Link','Description', 'ArtworkStyleID', 'DateStart', 'DateEnd', 'Country');
//validation rules
$crud->required_fields('Roll_Name','Link');
$crud->set_rules('DateStart', 'Earliest Date', 'integer');
$crud->set_rules('DateEnd', 'Latest Date', 'integer');
//foreign key settings
$crud->set_relation('ArtworkStyleID', 'ArtworkStyles', 'Artwork_Style_Name');
$crud->set_relation('Country', 'Countries', 'Country_Name');
//column and field labels
$crud->display_as('Roll_Name', 'Roll of Arms Name');
$crud->display_as('ArtworkStyleID', 'Artwork Style');
$crud->display_as('DateStart', 'Earliest Date');
$crud->display_as('DateEnd', 'Latest Date');
//display links correctly
$crud->callback_column('Link', array($this,'callback_webpage_handler'));
$crud->set_subject('Roll of Arms');
$crud->set_table('Rolls');
//set paging options
$this->config->load('grocery_crud');
$this->config->set_item('grocery_crud_default_per_page', '1000');
$crud->set_paging_options(array('10','25','50','100','1000'));
//set sorting. TODO: Sort options
$crud->order_by('Roll_Name');
$output= $crud->render($data['username']);
$this->load->view('listview.php',$output);
}
function logout()
{
$this->session->unset_userdata('logged_in');
$this->session->sess_destroy();
redirect('roll_c/rolls', 'refresh');
}
function callback_webpage_handler($value, $row)
{
$url = $row->Link;
if ($url[0] == '#') //trim leading and trailing '#' signs.
{
$url = substr($url, 1, (strlen($url)-2));
}
return "<a href='".$url."'>Link</a>";
}
}
?>