0

Я пытаюсь заполнить весь результат из базы данных в форме zend, но не могу работать.Как заполнить многоуровневый массив в форме zend

Это моя форма

$configsForm= new Zend_Dojo_Form_SubForm(); 

    $configsForm->setAttribs(array(
     'name'   => 'mandatory', 
     'legend'  => 'mandatory', 
     'dijitParams' => array(
      'title'  => $this-> view -> __ ('Configs'), 
     ) 
    )); 
    $configsForm->addElement(
     'FilteringSelect', 
     'group_id', 
     array(
      'label' => $this-> view -> __ ('Configs_Group Key'), 
      'required' => true, 
      'value'  => '', 
      'multiOptions' => $this->_getConfigOptions(), 
      'id'  => 'group_id', 
     ) 
    ); 
    $configsForm->addElement(
     'ValidationTextBox', 
     'option_type', 
     array(
      'label'  => $this-> view -> __ ('Configs_Option Type If Exist'), 
      'trim'  => true, 
      'required' => false, 
      'name'  => 'option_type', 
      'id'  => 'option_type', 
      'class'  => 'lablvalue jstalgntop', 
     ) 
    );  
    $configsForm->addElement(
     'ValidationTextBox', 
     'option_title', 
     array(
      'label'  => $this-> view -> __ ('Configs_Option Title'), 
      'trim'  => true, 
      'required' => true, 
      'class'  => 'lablvalue jstalgntop', 
     ) 
    ); 
    $configsForm->addElement(
     'ValidationTextBox', 
     'option_value', 
     array(
      'label'  => $this-> view -> __ ('Configs_Option Value'), 
      'trim'  => true, 
      'required' => true, 
      'class'  => 'lablvalue jstalgntop', 
     ) 
    ); 
    $configsForm->addElement(
     'select', 
     'option_status', 
     array(
      'label'   => $this-> view -> __('Configs_Option Status'), 
      'required'  => true, 
      'value'   => '', 
      'multiOptions' => array('' => $this -> view -> __('Root'), 0 => 'Disabel', 1 => 'Enabel'), 
     ) 
    ); 
    $configsForm->addElement(
     'FilteringSelect', 
     'locale_id', 
     array(
      'label' => $this-> view -> __ ('Configs_Locale'), 
      'class' => 'lablvalue jstalgntop', 
      'autocomplete'=>false, 
      'required' => true, 
      'multiOptions' => $this->_getLocaleOptions(), 
      'id' => 'locale_id', 
     ) 
    ); 
    $configsForm->addElement(
     'ValidationTextBox', 
     'option_hint', 
     array(
      'label'  => $this-> view -> __ ('Configs_Option Hint'), 
      'trim'  => true, 
      'required' => false, 
      'class'  => 'lablvalue jstalgntop', 
     ) 
    ); 
    $configsForm->addElement(
     'ValidationTextBox', 
     'option_description', 
     array(
      'label'  => $this-> view -> __ ('Configs_Option Description'), 
      'trim'  => true, 
      'required' => false, 
      'class'  => 'lablvalue jstalgntop', 
     ) 
    ); 
    $configsForm->addElement(
     'ValidationTextBox', 
     'comments', 
     array(
      'label'  => $this-> view -> __ ('Configs_Option Comments'), 
      'trim'  => true, 
      'class'  => 'lablvalue jstalgntop', 
      ) 
    ); 
    $configsForm->addElement(
     'hidden', 
     'id' 
    ); 


    $configsForm->addElement(
     'SubmitButton', 
     'submit', 
     array(
      'value'  => 'submit', 
      'label'  => $this-> view -> __ ('Object_Save'), 
      'type'  => 'Submit', 
      'ignore' => true, 
      'onclick' => 'dijit.byId("add-edit").submit()', 
     ) 
    ); 
    $configsForm->addElement(
     'reset', 
     'reset', 
     array(
      'label' => 'Reset', 
      'id' => 'reset', 
      'ignore'=> true, 
     ) 
    ); 

    $configsForm ->setDecorators (array ('FormElements', array ('HtmlTag', array ('tag' => 'table', 'class'=>'formlist')), 'ContentPane')); 
    $configsForm->setElementDecorators(array(
    'DijitElement', 
    'Errors', 
     array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'lable jstalgntop')), 
     array('Label', array('tag' => 'td', 'class' => 'lable jstalgntop')), 
     array(array('row' => 'HtmlTag'), array('tag' => 'tr')), 
    )); 

    $this->addSubForm($configsForm, 'configs'); 
} 

И код в мой контроллер выглядит

$form -> populate($configsObjResults); 

В $configsObjResults containes

Array 
(
    [0] => Array 
    (
     [id] => 11 
     [group_id] => 2 
     [group_key] => advanced 
     [option_title] => advanced.iptable.status 
    ) 

    [1] => Array 
    (
     [id] => 12 
     [group_id] => 2 
     [group_key] => advanced 
     [option_title] => advanced.memchache.iptable 
    ) 

) 
+0

У вас есть ошибки? – Config

+0

Нет, но форма не заполнилась! – user1476552

+0

Как я могу сгенерировать необходимые подформы в зависимости от количества массивов из БД для заполнения результата! – user1476552

ответ

1

Поместите свой код подчиненной в методе, называемом addConfigSubForm() в ваш код формы, например:

class myForm extends Zend_Dojo_Form 
{ 
    ... 

    // $number - 1st, 2nd, 3rd... subform 
    // $data - data to populate 
    public function addConfigSubForm($number, $data) 
    { 
     [ Create your subform here ] 

     // populate it with $data 
     $configsForm->populate($data); 

     // add it to the form 
     $this->addSubForm($configsForm, 'configs' . $i); 
    } 
} 

Тогда в контроллере, сделайте следующее:

$myform = new myForm(); 
foreach ($configsObjResults as $i=>$config) { 
    $myform->addConfigSubForm($i, $config); 
} 

Это добавит подчиненный для каждой конфиги объекта в массиве.

+0

** Stardev ** ты мой МАААААН! спасибо – user1476552

Смежные вопросы