本文整理汇总了PHP中Zend\Form\FormInterface::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::prepare方法的具体用法?PHP FormInterface::prepare怎么用?PHP FormInterface::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::prepare方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Outputs message depending on flag
*
* @param FormInterface $form
* @param array $staticElements
* @param null $formClass
*
* @return string
*/
public function __invoke(FormInterface $form, array $staticElements = [], $formClass = null)
{
$submitElements = [];
/** @var Form $form */
$form->setAttribute('role', 'form');
if ($formClass == 'form-inline') {
$form->setAttribute('class', $formClass . ' pull-right');
} elseif ($formClass) {
$form->setAttribute('class', $formClass);
} else {
$formClass = $form->getAttribute('class');
}
$form->prepare();
$output = $this->getView()->form()->openTag($form);
foreach ($staticElements as $element) {
$viewModel = new ViewModel();
$viewModel->setVariable('label', $element['label']);
$viewModel->setVariable('value', $element['value']);
$viewModel->setTemplate('travello-view-helper/widget/bootstrap-form-static');
$output .= $this->getView()->render($viewModel);
}
list($output, $submitElements) = $this->renderElements($form, $formClass, $output, $submitElements);
if ($formClass == 'form-inline') {
$template = 'bootstrap-form-submit-inline';
} else {
$template = 'bootstrap-form-submit';
}
$viewModel = new ViewModel();
$viewModel->setVariable('submitElements', $submitElements);
$viewModel->setTemplate('travello-view-helper/widget/' . $template);
$output .= $this->getView()->render($viewModel);
$output .= $this->getView()->form()->closeTag();
return $output;
}
示例2: __construct
/**
* @param FormInterface $form
* @param RendererInterface $renderer
*/
public function __construct(FormInterface $form, RendererInterface $renderer)
{
$this->form = $form;
if ($form instanceof ZendForm) {
$form->prepare();
}
$this->renderer = $renderer;
}
示例3: __invoke
/**
* Outputs message depending on flag
*
* @return string
*/
public function __invoke(FormInterface $form, $class = 'form-horizontal')
{
$submitElements = [];
$form->setAttribute('class', $class . ' well');
$form->setAttribute('role', 'form');
$form->prepare();
$output = $this->getView()->form()->openTag($form);
foreach ($form as $element) {
if ($element instanceof Submit || $element instanceof Button) {
$submitElements[] = $element;
} elseif ($element instanceof Csrf || $element instanceof Hidden) {
$output .= $this->getView()->formElement($element);
} elseif ($element instanceof Collection) {
$output .= $this->getView()->formCollection($element);
} elseif ($element instanceof Checkbox) {
// setup view model
$viewModel = new ViewModel();
$viewModel->setVariable('element', $element);
$viewModel->setTemplate('zf2rapid-library/widget/bootstrap-form-checkbox');
// render form element
$output .= $this->getView()->render($viewModel);
} else {
$element->setAttributes(['class' => 'form-control']);
$element->setLabelAttributes(['class' => 'col-sm-2 control-label']);
// setup view model
$viewModel = new ViewModel();
$viewModel->setVariable('element', $element);
$viewModel->setTemplate('zf2rapid-library/widget/bootstrap-form-group');
// render form element
$output .= $this->getView()->render($viewModel);
}
}
// setup view model
$viewModel = new ViewModel();
$viewModel->setVariable('submitElements', $submitElements);
$viewModel->setTemplate('zf2rapid-library/widget/bootstrap-form-submit');
// render submit elements
$output .= $this->getView()->render($viewModel);
$output .= $this->getView()->form()->closeTag();
return $output;
}