[eluser]taro uma[/eluser]
I've seen that and it helped some, I was able to create the MY_Controller based on that info. But I still can't see how to get the variables from MY_Controller to the controller that is extending it.
Here is what I have so far, I just can't get the $data from MY_Controller to pass along.
Code:
class MY_Controller extends Controller {
function MY_Controller()
{
// load controller parent
parent::Controller();
$this->data['sitewide']['mainNav'] = $this->getMainNav();
$this->data['sitewide']['sideBar'] = $this->getSideBar();
$this->data['sitewide']['footer'] = $this->getFooter();
}
private function getMainNav()
{
$mainNav = "asdfg1";
return $mainNav;
}
private function getSideBar()
{
$sideBar= "asdfg2";
return $sideBar;
}
private function getFooter()
{
$footer= "asdfg3";
return $footer;
}
}
but it's not giving me those variables in a control that extends it:
Code:
class FrontPage extends MY_Controller {
function __construct(){
parent::MY_Controller();
}
function index()
{
$this->load->model('FrontPageModel','',TRUE);
$data['frontpagedata'] = $this->FrontPageModel->get_frontpage_content();
$this->load->view('frontpage',$data);
}
}
This passes $data along to my view, which just echos out the $data variables (right now).
I am expecting $sitewide to be an array that exists with my site wide stuff in it. But it doesn't, so I know I'm doing it wrong. the load->view is passing $data along, because in the view I have the $frontpagedata, which is an array of that builds the content part of the page. But trying to use $sitewide , like echo $sitewide['mainNav') gives me as error
"Message: Undefined variable: sitewide"
So I see where I'm doing it differently as far as not loading a view in MY_Controller, from the example you show. But I can't see why the variables aren't in the $data array.
In my view, I have this:
Code:
<?php echo $sitewide['mainNav']; ?>
and it returns this error message:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: sitewide
Filename: views/frontpage.php
Line Number: 34