I've read through the source code but it seems a little cryptic. I'm just trying to get my head around how CI transforms an array into individual variables available to the view.
I gather that the view is included with include(), but the variables seem to only be effective for the view.
Controller:
$this->load->view('about', array('title' => 'about'));
View:
<?php echo $title; // shows 'about' ?>
Loading a View To load a particular view file you will use the following method: $this->load->view('name'); Where name is the name of your view file.
$data=array($var1,$var2); $this->load->view('myview',$data);
php extract() function
$array = array('test' => 'val', 'key' => 'value');
extract($array);
var_dump($test);
var_dump($key);
The variables $test and $key would be "visible" in the view only if they are declared localy, so let's say a function includes the view file and right before including it, it will extract the values, then the variables would be visible only inside that function ( witch body would contain the view file too ), it's not realy how CI does it but it explains the principle .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With