09-03-2009, 02:20 AM
[eluser]Dam1an[/eluser]
You would need to use $this to reference the data array in all your functions, like so
Also, passing $data into the function is a bad idea, unless you plan on having serialized arrays in the URL?
You would need to use $this to reference the data array in all your functions, like so
Code:
<?php
class Sample_Controller extends Controller {
public $data;
public function __construct() {
parent::__construct();
$this->data = array();
$this->data['active_menu'] = 'Menu One';
}
public function function_one() {
$this->data['page_title'] = 'Sample Page Title';
//$data['active_menu'] is passed to the main view
$this->load->view($this->main_view, $this->data);
}
public function function_two() {
$this->data['page_title'] = 'Another Page Title';
//Override the default $data['active_menu'] value
$this->data['active_menu'] = 'new value';
$this->load->view($this->main_view, $this->data);
}
}
Also, passing $data into the function is a bad idea, unless you plan on having serialized arrays in the URL?
