I am not actually asking the syntax and the how do it. That, I got it from: codeigniter: pass array from controller to view
I need to ask how actually it works and what the reason for the process.
I have a controller class with func..
public function index()
{
//echo 'hello world';
$this->load->model('Site_model');
var_dump($this->Site_model->getAll()); // just to troubleshoot
$data['a'] = $this->Site_model->getAll();
var_dump($data); // just to troubleshoot
$this->load->view('home', $data);
}
When I try to access the $data array directly in view
It throws error and need to be accessed instead as <?php var_dump($a); ?>
Why can't we directly use this
public function index()
{
//echo 'hello world';
$this->load->model('Site_model');
var_dump($this->Site_model->getAll()); // just to troubleshoot
$data = $this->Site_model->getAll();
var_dump($data); // just to troubleshoot
$this->load->view('home', $data);
}
and access the array as <?php var_dump($data); ?>
directly in view page