El Forum
10-06-2010, 07:23 AM
[eluser]Bleeding Edge Productions[/eluser]
Hi guys,
I am trying to extend Controller with a class MY_Controller. My code is:
This is saved as application/libraries/MY_Controller.php
Then, I have a controller called Homepage:
saved as application/controllers/Homepage.php
The view (main.php) is a simple HTML file echoing the variables $base and $assets.
But, it seems not to be working, and I think it's something to do with the way I'm extending Controller, because having "class Homepage extends Controller" works (aside from the PHP errors because $base and $assets are not defined), but using MY_Controller doesn't work.
Any help appreciated!
Thanks,
Martin
Hi guys,
I am trying to extend Controller with a class MY_Controller. My code is:
Code:
class MY_Controller extends Controller {
/**
* Instantiate any required site-wide variables
*/
protected $base; // Base URL of site
protected $assets; // Path to assets folder
// --------------------------------------------------------------------
/**
* Constructor - sets site-wide variables
*/
public function __construct() {
parent::Controller(); // Call the parent constructor
$this->base = $this->config->item('base_url');
$this->assets = $this->config->item('assets');
}
}
This is saved as application/libraries/MY_Controller.php
Then, I have a controller called Homepage:
Code:
class Homepage extends MY_Controller {
/**
* Constructor - inherits site-wide variables from MY_Controller.
*/
public function __construct() {
parent::__construct();
}
// --------------------------------------------------------------------
/**
* Generate the page
*/
function index(){
/**
* Assign variables to the $pagevars array
*/
$pagevars['base'] = $this->base;
$pagevars['assets'] = $this->assets;
/**
* Load the view
*/
$this->load->view('main', $pagevars);
}
}
saved as application/controllers/Homepage.php
The view (main.php) is a simple HTML file echoing the variables $base and $assets.
But, it seems not to be working, and I think it's something to do with the way I'm extending Controller, because having "class Homepage extends Controller" works (aside from the PHP errors because $base and $assets are not defined), but using MY_Controller doesn't work.
Any help appreciated!
Thanks,
Martin