[eluser]esra[/eluser]
To make them available across multiple controllers on an application-wide basis, you need to create a base controller (an application controller) and extend all other controllers from that application controller.
A sample Application controller:
Code:
<?php
class Application extends Controller {
function Application()
{
parent::Controller();
$this->load->helper( array('link', 'html', 'file') );
$this->load->library('validation');
$this->load->library('view');
}
function index()
{
//... local construction code here
}
}
?>
A controller subclassed from the Application controller:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH.'libraries/application'.EXT);
class Articles extends Application {
function Articles()
{
parent::Application();
$this->lang->load('articles', 'en_us');
}
function index()
{
// ... some controller specfic constructor code
$component = $this->lang->line('articles_component');
$page = $this->lang->line('articles_title');
$this->view->set('title', $page);
$this->view->set('comp', $component);
$this->view->part('nav', 'nav');
$this->view->part('content', 'content');
$this->view->part('inner1', 'inner1');
$this->view->part('inner2', 'inner2');
$this->view->load('nested');
}
}
?>
Be sure to add the require line of code to include the application controller in your subclassed controllers. I store my application controllers in libraries, but you can store them in controllers/ or elsewhere by setting the path to suit your needs. You can have multiple base controllers. For example, you could have an Admin controller and create Admin controllers based on it.
In the example above, the helpers and libraries loaded in the Application controller are inheirited by the Articles controller and whatever other controllers are extended from the Application controller.