在 Zend 2 中检索静态下拉数据并将其发布到 mysql 数据库中

Retrieving and posting static dropdown data into mysql database in Zend 2

我的表单中有几个字段希望 post 到数据库。所有其他字段 bar 下拉字段都工作正常

zend 2 的官方文档并不清楚如何处理post将下拉菜单中的数据输入数据库

这是我拥有的:

控制器中的addAction

public function addAction()
    {
        $form = new UsersForm();
        $form->get('submit')->setValue('Add');

        $request = $this->getRequest();
        if ($request->isPost()) 
        {
            $users = new Users();
            $form->setInputFilter($users->getInputFilter());
            $form->setData($request->getPost());

            if ($form->isValid()) 
            {
                $users->exchangeArray($form->getData());
                $this->getUsersTable()->saveUser($users);

                // Redirect to list of albums
                return $this->redirect()->toRoute('index');
            }
        }
        return array('form' => $form);

    }

我的表格

public function __construct($name = null)
    {
        // we want to ignore the name passed
        parent::__construct('users');

        //other form elements...

        //the dropdown menu
$this->add(array(
            'type' => 'Select',
            'name' => 'groupid',
            'options' => array(
                'label' => 'Group',
                'value_options' => array(
                    '0' => 'Not Selected',
                    '1' => 'Super Admin',
                    '2' => 'Company Admin',
                ),
            ),

        ));  
        //...
        }
}

风景

<?php
$form->setAttribute('action', $this->url('user', array('action' => 'add')));
$form->prepare();

echo $this->form()->openTag($form);
echo $this->formRow($form->get('groupid'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();

当我 运行 我申请 addAction 时,我收到一条错误消息: 无法执行语句(23000 - 1048 - 列 'GroupID' 不能为空)

其中 'GroupID' 是我的 table 中的列,它从下拉列表中获取值,这意味着该字段不是 post埃德

我需要这方面的帮助

如果数据库中的列是 GroupID,表单元素也应命名为该列。你的是 groupid(即小写)。如果这不能解决问题,请编辑您的问题以包含数据库结构和 saveUser() 函数的代码。