Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
form select via ORM
  • I want to follow instruction from here

    I Generate via oil scaffold, and then want to modify some form-input into    form-select

    in my controler action_create
    $data['kdbrgs']=Model_Kdbrg::find('all);
    $this->template->content = View::forge('kdbrg/create',$data);

    View create
    <?php echo render('kdbrg/_form'); ?>

    View _form 
    <?php echo Form::select('kdbrg', 'none', \Arr::pluck($kdbrgs, 'name','code')); ?>

    and then I get error message Undefined variable: kdbrgs

    but when I change my code to:
    n my controler action_create
    $data['kdbrgs']=Model_Kdbrg::find('all);
    $this->template->content = View::forge('kdbrg/othercreate',$data);

    View othercreate
    <?php echo Form::select('kdbrg', 'none', \Arr::pluck($kdbrgs, 'name','code')); ?>

    it works.., 

    I used to use in my view from standar oil scaffoling 
    DB::select()->from('kdbrg')->as_array () 
    but as the forum suggest it's not safe to do that, I want to change the way I make select
    can someone explain it for me how to do it correctly
    to make my apps more secure??

    regards.., thanks for any advise :)
  • HarroHarro
    Accepted Answer
    Your first example uses sub-views, and data isn't automatically inherited by those views. The fact that you pass a variable to "kdbrg/create" doesn't mean "kdbrg/_form" can see it, so you need to pass it on.

    To do that, change

    <?php echo render('kdbrg/_form'); ?>

    to

    <?php echo render('kdbrg/_form', array('kdbrgs' => $kdbrgs)); ?>


  • :D it works..,
    deeply thanks @Harro

Howdy, Stranger!

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

In this Discussion