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

How to pass a result of search in a Controller to Select tag in phtml view?

In my controller I have this portion of a code:

$providers = Providers::find();

and in my view I have :

    echo $this->tag->Select(
        [
        'prodID',
        $providers , // variable from controller , to populate select tag
        'using' =>[
        'id',
        'name',
            ]
        ]
        );

How to pass the result of Find method from controller to select tag ?

And an another question - is it possible (and how) to set "id" and "name" of select tag separately ?

thanks in advance for your help :)



6.4k
Accepted
answer

in controller

$this-view->setVar('providers', $providers);

https://docs.phalcon.io/3.4/en/views#value-transfer

echo $this->tag->Select(
  [
    'prodID',
    $providers, // variable from controller , to populate select tag
    'using' => [
      'id',
      'name',
    ],
    'id' => 'myId',
    'name' => 'myName'
  ]
);