We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

Render form select from database

Hello,

how can i render a dropdown from database.

For example from table Users

Form.php

        $users = Users::find();

        $usersSelect =  new Select("users",array(
                 $users, array(
                "using"      =>
                    "id",
                    "name",
                ),
                "useEmpty"   => true,
                "emptyText"  => "Please, choose one...",
                "emptyValue" => "@"
            )

        );

        $this->add($users);

Volt

        {{ form.render('users') }}

Thx



22.6k
Accepted
answer
edited Dec '16

From their example (provided), looks like you may have an extra array in there


 $this->add(
            new Select(
                "telephoneType",
                TelephoneTypes::find(),
                [
                    "using" => [
                        "id",
                        "name",
                    ]
                ]
            )
        );


59.7k

Hello Trent,

it is working, thx for that.

Rgds Stefan