Welcome Guest, Not a member yet? Register   Sign In
How CodeIgniter do the data parsing from array?
#1

[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
#2

[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.
#3

[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-gui...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.
#4

[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-gui...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




Theme © iAndrew 2016 - Forum software by © MyBB