在生成表单时,我需要在ZF2中从我的数据库中填写"select“选项(不使用Doctrine)。我的表单:
class RegisterTeacherForm extends Form
{
....
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'RegisterTeacherCountry',
'attributes' => array(
'id' => 'country_id',
'class' => 'selectable',
'autocomplete' => 'off',
),
'options' => array(
'value_options' => array(
'default' => 'Please Select',
'Austria' => 'Austria', //how i do fill this section from DB?
'France' => 'France',
'Germany' => 'Germany',
'Spain' => 'Spain',
),
),
));
}
感谢所有人的回复!
发布于 2013-12-10 17:12:54
如果您使用的是理论,请执行以下操作:
$this->add(array(
'name' => 'RegisterTeacherCountry',
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'attributes' => array(
'id' => 'country_id',
'class' => 'selectable',
'autocomplete' => 'off',
),
'options' => array(
'object_manager' => $this->getEntityManager(),
'target_class' => 'YOUR ENTITY NAMESPACE',
'property' => 'your db collumn name',
'disable_inarray_validator' => true,
'by_reference' => false,
'is_method' => true,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array(),
'orderBy' => array('nameOfCollumnYouWantToOrderBy' => 'ASC'),
),
),
),
));
https://stackoverflow.com/questions/20490117
复制相似问题