Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to pass value to select input in a form from controller
  • 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
  • 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.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion