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

Populate Select Form Element by a RAW SQL query

Hello guys!

I'm wondering about the structure of the "object" or "array" to pass to a view variable for being used in a Select form element.

My actual variable looks like.

array (size=4)
  0 => 
    array (size=2)
      'id' => string '60' (length=2)
      'name' => string 'ClientOne' (length=9)
  1 => 
    array (size=2)
      'id' => string '61' (length=2)
      'name' => string 'ClientTwo' (length=9)
  2 => 
    array (size=2)
      'id' => string '62' (length=2)
      'name' => string 'ClientThree' (length=11)
  3 => 
    array (size=2)
      'id' => string '63' (length=2)
      'name' => string 'ClientFour' (length=10)

In my volt tempalte I have something like this:

        {{ select('client', clients, 'using': ['id', 'name'], 'id' : 'client', 'required' : 'required',  'class' : 'form-control') }}

What is wrong?



13.8k
Accepted
answer
edited Jan '18

Found it!

Are associative arrays like array( 'id_val' => 'name_val');