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



9.3k
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",
                    ]
                ]
            )
        );


21.5k

Hello Trent,

it is working, thx for that.

Rgds Stefan