<?php
/**
* This is my own custom controller. It adds support for .extension in the url, and it provides a shortcut to the view function. So that in the children you wont have to type so much.
*
*/
class My_Controller extends Controller {
/**
* Contains the layout/extension for the current view.
*
* @var string
*/
protected
$layout = 'xhtml';
protected
/**
* Controls startup options.
*
*/
function __construct() {
parent::__construct();
$this->output->enable_profiler();
$this->
load->
library('My_Library',
array());
}
/**
* This function remaps the url and retrieves the desired extension from it. It then calls the appropiate controller method.
*
* @param string $aMethod
*/
function _remap($aMethod) {
$lParams = $this->uri->segment_array();
$lMethod = $aMethod;
if (strpos($lMethod,
'.') !==
False)
list($lMethod,
$this->
layout) =
explode('.',
$lMethod);
$lMethod =
(empty($lMethod) ?
'index' :
$lMethod);
} else {
show_404($lMethod);
}
}
/**
* This function provides a shortcut to the load->view function. It also appends the current layout so you won't get lost.
*
* @param string $aView
*/
function view
($aView,
$aData=
array()) {
$aData['cssFiles'] = $this->cssFiles;
$aData['jsFiles'] = $this->jsFiles;
$this->load->view($this->layout.DIRECTORY_SEPARATOR.$aView, $aData);
}
/**
* Uses the last segment to read the querystring. Use this to relieve you from the absence of GET in CI.
*
* @return array
*/
function getQuery() {
$segs = $this->uri->total_segments();
if ($segs>2) {
$qs = $this->uri->segment($segs);
return $data;
} else {
return null;
}
}
/**
* This function is to register the css files you want to use with this controller.
*
* @param string $aCSSFile
*/
function registerCSSFile($aCSSFile) {
$this->cssFiles[] = $aCSSFile;
}
/**
* This function is to register the javascript files you want to use with this controller.
*
* @param string $aJSFile
*/
function registerJSFile($aJSFile) {
$this->jsFiles[] = $aJSFile;
}
}
?>