早上好,尝试为数据库创建一个动态选择值,但是你可以添加一个foreach这个选择吗?
$table = new Application_Model_DbTable_Artista();
$nombre = array();
foreach ($table->listar() as $c)
{
$id = $c->id;
$nombre[$id] = $c->nombre;
}
$this->addElement('select','artista_id',
array(
'value' => 'white',
'multiOptions' => array($nombre
),
'decorators' => array('ViewHelper', 'Errors'),
)
);
答案 0 :(得分:0)
完全可以。
$roles = $roleTable->fetchAll();
$selRol = array();
foreach($roles as $role) {
$id = $role->getId();
$selRol[$id] = $role->getName();
}
$this->setAttribute('method', 'post');
$this->add(array(
'name' => 'username',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Usuario',
),
));
$this->add(array(
'name' => 'password',
'attributes' => array(
'type' => 'password',
),
'options' => array(
'label' => 'Clave',
),
));
$this->add(array(
'name' => 'email',
'attributes' => array(
'type' => 'email',
),
'options' => array(
'label' => 'Email',
),
));
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'role_id',
'options' => array(
'label' => 'Role',
'value_options' => $selRol,
),
));