ZF2 Form \ Element \ MultiCheckbox: how to get each element in a new line?

I exposed it to no avail. I have an item with multiple cells in one of my forms. Here is the code I used to create it:

$this->add(array (
    'name' => 'thingyId',
    'type' => 'MultiCheckbox',
    'options' => array (
        'value_options' => $thingyArray,
    )
));

In my opinion a script, I have this:

<?= $this->formRow($form->get('thingyId')); ?>

The form element displays fine, but all the checkboxes are on the same line. How to do this so that each flag is on a new line?

+3
source share
2 answers

If you look at the link you will see that the fourth argument is partial. Thus, you can use many ways to accomplish a task.

Method 1:

echo $this->formRow($element, null, null, 'template-file');

Now create a template file with a name template-file.phtmlto render the element as you like.

//template-file.phtml
<span><?php echo $label; ?></span><br/>
<?php foreach ($element->getValueOptions() as $key => $value): ?>
    <input type="checkbox" name="<?php echo $element->getName() ?>[]" value="<?php echo      $value; ?>">
    <span><?php echo $key; ?></span><br/>
<?php endforeach; ?>

Method 2

, .

namespace Application\View\Helper;

class MyFormRow extends \Zend\Form\View\Helper\FormRow
{
       /**
        * @var string
        */
       protected $partial = 'template-file';
}

,

namespace Application;

class Module 
{
    public function getViewHelperConfig()
    {
        return array(
            'invokables' => array(
               'myFormRow' => 'Application\View\Helper\MyFormRow'
            )
        );
    }
}

, :

echo $this->myFormRow($element);
+9

, . :

<?php
$oMultiCheckboxField = $oForm->get('multicheckboxelement');
echo $this->formMultiCheckbox($oMultiCheckboxField);
?>

, formMultiCheckbox, : .

:

<?php
$oMultiCheckboxField = $oForm->get('multicheckboxelement');
$oMultiCheckboxViewHelper = new \Zend\Form\View\Helper\FormMultiCheckbox();
$oMultiCheckboxViewHelper->setSeparator('<hr>');
echo $oMultiCheckboxViewHelper->render($oMultiCheckboxField);
?>

, , ZF1 (, , , , ). ZF2, . , , , .

0

All Articles