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?

  • 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'))
        ->order_by('fullname', 'ASC')
         >as_array('id', 'fullname');

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

    // set the users list as options for a form select dropdpwn
        ->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


Howdy, Stranger!

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

In this Discussion