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 get select tab in volt

i want to show db values as dropdown list in a table...but i am not able to do the same...can anyone help??

below is my code

<tr>
            <td>{{ table.id }}</td>
            <td>{{ table.name }}</td>
                <td> {{ select("name","role","using": ["id", "name"])}} </td> 

<td width="7%">{{  radio_field("access", "value": "grant") }}   Grant  </td>
<td width="7%">{{  radio_field("access", "value": "deny") }}   Deny  </td>              

        </tr>

when i tried the above code ... iam got the following error...

            Invalid data provided to SELECT helper
#0 [internal function]: Phalcon\Tag\Select::selectField(Array, NULL)
#1 C:\wamp64\www\project\cache\volt\c%%%%wamp64%%www%%corporate_reimbursement%%app%%views%%permission%%assign.volt.php(26): Phalcon\Tag::select(Array)
#2 [internal function]: unknown()
#3 [internal function]: Phalcon\Mvc\View\Engine\Volt->render('C:\\wamp64\\www\\c...', Array, true)
#4 [internal function]: Phalcon\Mvc\View->_engineRender(Array, 'permission/assi...', true, true, NULL)
#5 [internal function]: Phalcon\Mvc\View->render('permission', 'assign', Array)


43.9k
edited Oct '16

Hi,

Invalid data provided to SELECT helper

[internal function]: Phalcon\Tag\Select::selectField(Array, NULL)

from the controller, you have to provide role list to the view :


// in your controller action
$roles = Role::find([  // I find more convenient to use plural here
    'columns' => 'id, name',
    'order' => 'name ASC'
]);
$this->view->setVar('roles', $roles);

// in your view
 <td> {{ select("name","roles","using": ["id", "name"])}} </td>


47.7k

@le51

I think you have a typo:

// in your controller action
$roles = Role::find([  // I find more convenient to use plural here
    'columns' => 'id, name',
    'order' => 'name ASC'
]);
$this->view->setVar('roles', $roles);

// in your view
 <td> {{ select("name", roles ,"using": ["id", "name"])}} </td>