Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
How to pass value to select input in a form from controller
sibinx7
March 2014
I want to pass a value from controller to a select input
type
in a form. I store everything (an array) in
$data['list_of_shops'], then i pass it using
$this->template->content = View::forge('cu\coupons/create',$data);
When i use var_dump($list_of_shops) in create view file, it works. But when i use same on _form.php it didn't work..
This is the code in create view page
<div class="col-md-12">
<?php echo render('cu\coupons/_form'); ?>
</div>
There is a _form.php in that folder. I pass $list_of_shops in the render as second parameter but didn't worked.
Details : I have a table of shops with id. I want to dynamically set values to the options in select input type.
Thanks in advance
Harro
March 2014
View variables are rendered in a local scope (views are rendered in a closure to be exact), so they are not available outside of it.
So if you have a variable in your main view, it is not available in a child view, unless you pass it on. So you need to use
<?php echo render('cu\coupons/_form', array('list of shops' => $list_of_shops)); ?>
to pass it on to the next view.
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,089
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
261
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
March 2014