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

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.7k
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.9k

Hello Trent,

it is working, thx for that.

Rgds Stefan