php - Codeigniter: What is the process behind data passing form controller to view? -


i not asking syntax , how it. that, got from: codeigniter: pass array controller view

i need ask how works , reason process.

i have controller class func..

public function index() {     //echo 'hello world';     $this->load->model('site_model');      var_dump($this->site_model->getall()); // troubleshoot      $data['a'] = $this->site_model->getall();     var_dump($data); // troubleshoot      $this->load->view('home', $data); } 

when try access $data array directly in view

it throws error , need accessed instead <?php var_dump($a); ?>

why can't directly use

public function index() {     //echo 'hello world';     $this->load->model('site_model');      var_dump($this->site_model->getall()); // troubleshoot      $data = $this->site_model->getall();     var_dump($data); // troubleshoot      $this->load->view('home', $data); } 

and access array <?php var_dump($data); ?> directly in view page

the procees being used behind simple one. uses php function.

extract($data); 

this lets keys used variables on view.

see docs here


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -