Skip to content

Instantly share code, notes, and snippets.

@vnagara
Forked from dmitrybelyakov/Controller.php
Last active August 29, 2015 13:57
Show Gist options
  • Save vnagara/9387100 to your computer and use it in GitHub Desktop.
Save vnagara/9387100 to your computer and use it in GitHub Desktop.
<?php
/**
* Example action
* This is an example action that tests binding of forms to entities.
* @return \Zend\View\Model\ViewModel
*/
public function exampleAction()
{
$node = new \ArrayObject(array(
'meta' => array(
'title' => 'Test',
),
'general' => array(
'slug' => 'test-item',
),
));
$form = new \Zend\Form\Form('example');
//meta
$meta = new \Zend\Form\Fieldset('meta');
$meta->add(new \Zend\Form\Element\Text('title', ['label' => 'Title']));
$form->add($meta);
//general
$general = new \Zend\Form\Fieldset('general');
$general->add(new \Zend\Form\Element\Text('slug', ['label' => 'Slug']));
$form->add($general);
$form->bind($node);
$response['form'] = $form;
$vm = new ViewModel(array('form' => $form));
$vm->setTemplate('example');
return $vm;
}
<?php $this->form->prepare(); ?>
<?= $this->form()->openTag($this->form) ?>
<?php foreach ($this->form as $elementOrFieldset): ?>
<?php if ($elementOrFieldset instanceof Zend\Form\Fieldset): ?>
<?= $this->formCollection($elementOrFieldset) ?>
<?php else: ?>
<?= $this->formRow($elementOrFieldset) ?>
<?php endif; ?>
<?php endforeach; ?>
<?= $this->formCollection($this->form->get('meta')) ?>
<?= $this->formCollection($this->form->get('general')) ?>
<?= $this->form()->closeTag() ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment