CodeIgniter Forums
How CodeIgniter do the data parsing from array? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How CodeIgniter do the data parsing from array? (/showthread.php?tid=6163)



How CodeIgniter do the data parsing from array? - El Forum - 02-16-2008

[eluser]Unknown[/eluser]
Hi folks,

Would anyone tell me how CodeIgniter do this?
In the controller call any view and pass an array of data inside. And in the view file, we can access to the data element directly.

Like this:
$data['var1'] = 'value 1';
$this->load->view( 'view_hello', $data);

and in view_hello.php we can use $var1.

I only can do: $this->var1 but not $var1 directly.


Great thanks and regards,
H


How CodeIgniter do the data parsing from array? - El Forum - 02-16-2008

[eluser]Rick Jolly[/eluser]
The php function extract():
http://ca3.php.net/extract

You could look at the CI Loader class to find out how it's used.


How CodeIgniter do the data parsing from array? - El Forum - 02-16-2008

[eluser]Chris Newton[/eluser]
Weird. In my views I always do exactly what you're talking about, without having to use $this->var1. In fact, the manual at:
http://ellislab.com/codeigniter/user-guide/general/views.html

shows exactly what you're requesting.

The only time I have to use $this->var is when I've set that variable OUTSIDE of the function calling the view... for instance when I set a variable in the constructor function.


How CodeIgniter do the data parsing from array? - El Forum - 02-16-2008

[eluser]Unknown[/eluser]
[quote author="Rick Jolly" date="1203215835"]The php function extract():
http://ca3.php.net/extract

You could look at the CI Loader class to find out how it's used.[/quote]

Thank you, that's exactly what I'm looking for.


[quote author="mahuti" date="1203222760"]Weird. In my views I always do exactly what you're talking about, without having to use $this->var1. In fact, the manual at:
http://ellislab.com/codeigniter/user-guide/general/views.html

shows exactly what you're requesting.

The only time I have to use $this->var is when I've set that variable OUTSIDE of the function calling the view... for instance when I set a variable in the constructor function.[/quote]
Nah, I'm coding my own script, not using CI Smile


Cheers Smile