We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Select tag "using" with more fields

Hello,

I need to concatenate 3 field to use in select options:

<?php echo \Phalcon\Tag::select(array(
                    "TiposEquip_id", 
                    Caracteristicas::find("nome = 'RAM'") , 
                    "using" => array("id","descricao"), 
                    'multiple' => 'multiple',
                    "class" => "form-control")) 
?>

I need the id plus another field wich is 3 filed concatenated. It's possible ?

thx CV

I'm using select in a slightly different way, than you do, but what you are asking for is possible in Phalcon, have a look at my answer on a different topic https://forum.phalcon.io/discussion/895/addoption-method-of-forms-element-select-object-does-not-seem-to

If you cannot do anything with that have a look at https://docs.phalcon.io/en/latest/reference/tags.html#making-select-boxes

It pretty much boils down to working with a result of find() method first and then adding it to select.

Take care.

I personally used a slightly different approach. I provided Model::find() with some parameters to resolve my problem which is a name stored in three different columns. It works perfectly for me.

//Parameters to use when fetching the agent_id object
$agent_params =  [
        'conditions'  => 'designation_id = "2" AND status = "1"',
        'columns'     => 'id, CONCAT(first_name," ",middle_name," ",last_name) AS name',
        'order'     => 'name'
];  
//define agent_id
$agent_id = new Select('agent_id', 
            User::find($agent_params),
            [
                'using'     => [ 'id','name'  ],
                'useEmpty'  => true,
                'emptyText' => 'Please Select Agent',
                'emptyValue'    => '',
            ]
);
$agent_id->setLabel("Agent");
$this->add($agent_id);