在Zend Form多选选项中填充值

时间:2014-04-04 10:28:42

标签: php zend-framework

所以我的表格是

class Form_Group_ShareGroup extends Form_Abstract
{
    public function init()
    {
        $this->setAttrib('class', 'shareForm');

        //Row 1
        $this->addElement('select', 'groups', array(
            'decorators' => $this->getElementDecorators(),
            'label' => Zend_Registry::get('Zend_Translate')->translate('Groups_Colon'),
            'style' => 'width:320px;',
            'multiple' => true,
            'data-help' => Zend_Registry::get('Zend_Translate')->translate('Please_Select_Groups_Share')
        ));

        $this->addElement('select', 'users', array(
            'decorators' => $this->getElementDecorators(),
            'label' => Zend_Registry::get('Zend_Translate')->translate('Users_Colon'),
            'style' => 'width:320px;',
            'multiple' => true,
            'data-help' => Zend_Registry::get('Zend_Translate')->translate('Select_Users_To_Share_Group_With')
        ));


        //Row 2
        $this->addElement('button', 'share', array(
            'decorators' => $this->buttonDecorators,
            'required' => false,
            'ignore'   => true,
            'type'     => 'submit',
            'label'    => 'Share',
            'class'    => 'btn primary'
        ));
    }
}

我希望将一些用户数据填充到“users”元素中。 例子可能是:

array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' )

我怎样才能做到这一点?

我使用了populate方法,但它没有成功。

查看我正在使用的表单:

$usersGroup = new Form_Group_ShareGroup();
$this->view->usersGroup = $usersGroup;

请帮忙! 谢谢你的阅读。

1 个答案:

答案 0 :(得分:0)

试试这个:

//$data = array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' );
$usersGroup = new Form_Group_ShareGroup();
$usersGroup->getElement('users')->setMultiOptions($data);