本文整理匯總了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;
}