[eluser]marcoss[/eluser]
[quote author="Rick Jolly" date="1183242120"]Question #1:
Question #2:
Use a class variable for $data to access it in more than one method of the same controller:
[/quote]
That will work if you want to use the data across the controller, but if yo have to pass a large amount of data like i do to the views to build the UI ¡dynamically using a common data structure, you can use a Model to store the structure and logic of the data you'll be passing to the views, just a simple example:
Code:
// Data Model
class DataModel extends Model {
function DataModel() {
parent::Model();
}
private $foo = array();
function set_foo($key='',$val=''){
$this->foo[$key] = $val;
}
function get_foo(){
return $this->foo;
}
}
// Controller using the Data Model
class Article extends Controller {
function Article(){
parent::Controller();
$this->load->model('DataModel');
$this->DataModel->set_foo('global_option', 'foo');
$this->DataModel->set_foo('another_global', 'bar');
}
function index(){
$this->DataModel->set_foo('title', 'Hello World');
$this->DataModel->set_foo('color', '#003322');
$this->DataModel->set_foo('sidebar', 'extended');
$data = $this->DataModel->get_foo();
$this->load->view('article', $data);
}
}
That is a simple example but you can think it like and active record approach and even add some logic to it so it will auto-populate fields left blank with some default values, that's up to you.