首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在zf2中动态填写表单

在zf2中动态填写表单
EN

Stack Overflow用户
提问于 2013-12-10 17:05:48
回答 1查看 393关注 0票数 1

在生成表单时,我需要在ZF2中从我的数据库中填写"select“选项(不使用Doctrine)。我的表单:

代码语言:javascript
运行
复制
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',
            ),
        ),
    ));
}

感谢所有人的回复!

EN

回答 1

Stack Overflow用户

发布于 2013-12-10 17:12:54

如果您使用的是理论,请执行以下操作:

代码语言:javascript
运行
复制
$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'),
                ),
            ),
        ),
    ));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20490117

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档