Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Select Method | ORM | Structure
  • Hi everyone.

    I need use
    but, isn't a simple select. The options come from DB data, i need that value to show is a label and the value to send from the form is the own id to that label.

    How to can do this?

    Thanks
  • HarroHarro
    Accepted Answer
    It is easier to use DB calls for that, and not ORM calls, the ORM isn't really suitable as a query builder, and doesn't have the options to easily return values in the correct format,

    Using DB:

    // get the list of users in an id => fullname format
    $users =  \DB::select('id', array(\DB::expr('CONCAT(surname,", ",initials," ",prefix)'), 'fullname'))
        ->from('userstable')
        ->order_by('fullname', 'ASC')
        ->execute()-
         >as_array('id', 'fullname');

    // create a placeholder
    $placeholder = array('' => __('global.forms.please-select'));

    // set the users list as options for a form select dropdpwn
    $form
        ->field('user_id')
        ->set_value($user_id)
        ->set_options($placeholder + $users);

    You can "hide" the query code in a static method of your model, using static::table() as the tablename, so you can do something like

    $form->set_options(Model_Users::get_dropdown_list($user_id));

Howdy, Stranger!

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

In this Discussion