Reputation: 23
I'm trying to declare the title variable in MY_Controller in the $data variable, to use it when I load the page so I do that:
function __construct()
{
parent::__construct();
$this->data['siteNamePrefix'] = "Mysite.com - ";
}
So when I loa my page in the method of a normale controller,
class Home extends MY_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
var_dump($data);
$this->load->view('home',$this->data);
}
I don't see in the var_dump the variable siteNamePrefix that I declared in MY_controller
Upvotes: 1
Views: 683
Reputation: 270637
Assuming the __construct()
at the top of your post is MY_Controller::__construct()
, you have correctly extended it.
In the object instance, you just need to be using $this
in the dump as well as in the load()
method that follows it:
public function index()
{
// $this->data should be defined here and correctly initialized
var_dump($this->data);
$this->load->view('home',$this->data);
}
Upvotes: 1