Forms 在zf2中动态填写表单
生成表单时,我需要从ZF2中的数据库(不使用条令)中填写“选择”选项。 我的表格:Forms 在zf2中动态填写表单,forms,frameworks,zend-framework2,Forms,Frameworks,Zend Framework2,生成表单时,我需要从ZF2中的数据库(不使用条令)中填写“选择”选项。 我的表格: class RegisterTeacherForm extends Form { .... $this->add(array( 'type' => 'Zend\Form\Element\Select', 'name' => 'RegisterTeacherCountry', 'attributes' => array(
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',
),
),
));
}
谢谢大家的回答 如果您正在使用条令,请执行以下操作:
$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'),
),
),
),
));
如果您正在使用条令,请执行以下操作:
$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'),
),
),
),
));
你在使用教义吗?你在使用教义吗?不,我不使用教义。我在ZF2中使用本机db connect through adapter我想是的,但我使用本机方法我不太习惯使用本机方法,但我想您可以运行一个查询,然后在控制器中使用
$form->get('RegisterTeacherCountry')->setValueOptions($yourresultsarray)代码>不客气!你应该选择答案,或者用你的解决方案创建一个新的答案来帮助他人!不,我不使用教义。我在ZF2中使用本机db connect through adapter我想是的,但我使用本机方法我不太习惯使用本机方法,但我想您可以运行一个查询,然后在控制器中使用$form->get('RegisterTeacherCountry')->setValueOptions($yourresultsarray)代码>不客气!你应该选择答案,或者用你的解决方案创建一个新的答案来帮助他人!