Welcome Guest, Not a member yet? Register   Sign In
php variable in html
#1

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

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

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

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB