[eluser]TheFuzzy0ne[/eluser]
You'd simply run the functions you need from within the controller's constructor.
Code:
class Blog extends Controller {
function Blog
{
parent::Controller(); # Don't forget to call the parent constructor!
$this->load->library('navigation');
$this->set_navigation();
}
// Should be executed in a hook maybe?
function set_navigation()
{
$this->navigation->add_item('Blog Home', 'blog');
$this->navigation->add_item('Blog Archive', 'blog/archive');
}
function index()
{
$data['title'] = 'Hello World!';
$data['nav_menu'] = $this->navigation->get_all();
$this->load->view('blog/home', $data);
}
function archive()
{
$data['title'] = 'Archive page';
$data['nav_menu'] = $this->navigation->get_all();
$this->load->view('blog/home', $data);
}
}
Or you can extend the controller class:
./system/application/libraries/MY_Controller.php
Code:
<?php
class MY_Controller extends Controller {
function MY_Controller()
{
parent::Controller(); # Call the parent constructor.
$this->_set_navigation();
}
function _set_navigation() # prefix with an underscore so it's not accessible from the outside.
{
# This will be overriden by your controller.
}
}
You're controllers would then need to extend MY_Controller, and you'd need to call parent::MY_Controller(); from within the constructor.