CodeIgniter Forums
php variable in html - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: php variable in html (/showthread.php?tid=15166)



php variable in html - El Forum - 01-28-2009

[eluser]Bluemagix[/eluser]
Hello,

I want to use one form(View)variable in to another form(view)
using the controller.
i have called the view page like this

http://localhost/category/upload/9/

where upload is my function in cotroller
from where i am calling the view page
and 9 is the argument passed to that function.


now if i want the value 9 in my view page
how can i get that in code igniter


php variable in html - El Forum - 01-28-2009

[eluser]The Wizard[/eluser]
say you have the variable $foo = '3'; in your controller,

you have to put it into the $data array like:

Code:
$data['foo'] = '3';

$this->load->view( 'blah.php', $data );

then in your html you do:
Code:
hello this is a HTML file. <br />
My Foo variable is: &lt;?php echo $foo?&gt; &lt;!-- WITHOUT $data!!! --&gt;
If this server supports short tags, i can write &lt;?= $foo ?&gt; too :)

take care.


php variable in html - El Forum - 01-28-2009

[eluser]Bluemagix[/eluser]
what if i have array


php variable in html - El Forum - 01-28-2009

[eluser]Bramme[/eluser]
Code:
$my_array = array("foo" => "bar", "some" => "shizzle");
$data['my_array'] = $my_array;
$this->load->view("myview", $data);

Easy as pie!

At first I didn't like this approach, but after working a while with CodeIgniter, this really works well. It's really handy when debugging for instance: just print_r the $data array and you see what variables you have in your view...


php variable in html - El Forum - 01-28-2009

[eluser]Bluemagix[/eluser]
but how can i access that in view??
suppose i want value of foo of data array
in view


php variable in html - El Forum - 01-29-2009

[eluser]Bramme[/eluser]
http://ellislab.com/codeigniter/user-guide/general/views.html