Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 :)



4.6k
Accepted
answer

in controller

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

https://docs.phalconphp.com/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'
  ]
);