当前位置: 首页>>代码示例>>PHP>>正文


PHP ElementInterface::getViewPartial方法代码示例

本文整理汇总了PHP中Zend\Form\ElementInterface::getViewPartial方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::getViewPartial方法的具体用法?PHP ElementInterface::getViewPartial怎么用?PHP ElementInterface::getViewPartial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Form\ElementInterface的用法示例。


在下文中一共展示了ElementInterface::getViewPartial方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderSummaryElement

 /**
  * Helper function to recurse into form elements when rendering summary.
  * 
  * @param ElementInterface $element
  * @return string
  */
 protected function renderSummaryElement(ElementInterface $element)
 {
     if ($element instanceof Hidden || false === $element->getOption('render_summary')) {
         return '';
     }
     if ($element instanceof ViewPartialProviderInterface) {
         $partial = $element->getViewPartial();
         $summaryPartial = $partial . '.summary';
         $partialParams = array('element' => $element);
         if (!$this->getView()->resolver($summaryPartial)) {
             $summaryPartial = $partial;
             $partialParams['renderSummary'] = true;
         }
         return $this->getView()->partial($summaryPartial, $partialParams);
     }
     if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) {
         $emptySummaryNotice = $this->getTranslator()->translate($element->getEmptySummaryNotice(), $this->getTranslatorTextDomain());
         $markup = sprintf('<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', $element->getAttribute('id'), $emptySummaryNotice);
         return $markup;
     }
     $label = $element->getLabel();
     $markup = '';
     if ($element instanceof FieldsetInterface) {
         if (!$element instanceof FormInterface && $label) {
             $markup .= '<h4>' . $label . '</h4>';
         }
         foreach ($element as $el) {
             $markup .= $this->renderSummaryElement($el);
         }
         return $markup;
     }
     $elementValue = $element instanceof \Zend\Form\Element\Textarea ? nl2br($element->getValue()) : $element->getValue();
     $markup .= '<div class="row">';
     $col = 12;
     if ($label) {
         $markup .= '<div class="col-md-3"><strong>' . $label . '</strong></div>';
         $col = 9;
     }
     $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>';
     return $markup;
 }
开发者ID:bitrecruiter,项目名称:CrossApplicantManager,代码行数:47,代码来源:SummaryForm.php

示例2: render

 /**
  * Utility form helper that renders a label (if it exists), an element and errors
  *
  * @param ElementInterface $element
  * @return string
  * @throws \Zend\Form\Exception\DomainException
  */
 public function render(ElementInterface $element, $ignoreViewPartial = false)
 {
     $labelAttributes = $element->getLabelAttributes();
     $labelWidth = $element->getOption('labelWidth');
     if (!$labelWidth) {
         $labelWidth = $this->labelSpanWidth;
     }
     if ($element instanceof ViewPartialProviderInterface && !$ignoreViewPartial) {
         return $this->getView()->partial($element->getViewPartial(), array('element' => $element, 'labelWitdh' => $labelWidth, 'label_attributes' => $labelAttributes));
     }
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $elementHelper = $this->getElementHelper();
     $elementErrorsHelper = $this->getElementErrorsHelper();
     $inputErrorClass = $this->getInputErrorClass();
     $elementErrors = $elementErrorsHelper->render($element);
     // general Class
     $form_row_class = 'row';
     if ($this->layout == Form::LAYOUT_HORIZONTAL) {
         $form_row_class = 'form-group';
     }
     // Does this element have errors ?
     if (!empty($elementErrors) && !empty($inputErrorClass) && $this->layout != Form::LAYOUT_BARE) {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . $inputErrorClass;
         $element->setAttribute('class', $classAttributes);
     }
     if (!$element->hasAttribute('id')) {
         $elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $element->getName());
         $element->setAttribute('id', $elementId);
     } else {
         $elementId = $element->getAttribute('id');
     }
     /*
      * add form-control class to all form elements, but "submit" or "reset" and Buttons!
      */
     if ($element->getAttribute('type') != 'submit' && $element->getAttribute('type') != 'reset' && $element->getAttribute('type') != 'checkbox' && !$element instanceof Button) {
         $element->setAttribute('class', $element->getAttribute('class') . ' form-control ');
     }
     $elementString = $elementHelper->render($element);
     $desc = $element->getOption('description', false);
     if ($desc && $this->layout != Form::LAYOUT_BARE) {
         if (null !== ($translator = $this->getTranslator())) {
             $desc = $translator->translate($desc, $this->getTranslatorTextDomain());
         }
         $elementString .= sprintf('<div id="%s-desc" class="cam-description alert alert-info">%s</div>', $elementId, $desc);
     }
     if (!$element instanceof \Zend\Form\Element\Hidden && !$element instanceof \Zend\Form\Element\Button && $this->layout != Form::LAYOUT_BARE) {
         $elementString .= sprintf('<div id="%s-errors" class="errors">%s</div>', $elementId, $elementErrors);
     }
     // moved label here so we can change it in the ElementViewHelper
     $label = $element->getLabel();
     if (isset($label) && '' !== $label && !$element instanceof \Zend\Form\Element\Button) {
         // Translate the label
         if (null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
         $label = $escapeHtmlHelper($label);
         $labelAttributes = $element->getLabelAttributes();
         if (empty($labelAttributes)) {
             $labelAttributes = $this->labelAttributes;
         }
         // Multicheckbox elements have to be handled differently as the HTML standard does not allow nested
         // labels. The semantic way is to group them inside a fieldset
         $type = $element->getAttribute('type');
         if ($type === 'multi_checkbox' || $type === 'radio') {
             $markup = sprintf('<fieldset><legend>%s</legend>%s</fieldset>', $label, $elementString);
         } else {
             if ($this->layout == Form::LAYOUT_BARE) {
                 $markup = $elementString;
             } else {
                 if (!isset($labelAttributes['for'])) {
                     $labelAttributes['for'] = $elementId;
                 }
                 if (Form::LAYOUT_HORIZONTAL == $this->layout) {
                     if (!isset($labelAttributes['class'])) {
                         $labelAttributes['class'] = '';
                     }
                     $labelAttributes['class'] .= ' control-label';
                 }
                 $element->setLabelAttributes($labelAttributes);
                 $label = $labelHelper($element);
                 if ($this->shouldWrap) {
                     $spanWidth = 12 - $labelWidth;
                     $elementString = sprintf('<div class="col-md-%d%s" id="' . $elementId . '-span">%s</div>', $spanWidth, $elementErrors ? " {$inputErrorClass}" : '', $elementString);
                     $label = sprintf('<div class="col-md-%d yk-label">%s</div>', $labelWidth, $label);
                 }
                 $markup = $label . $elementString;
             }
         }
     } else {
         if ($this->shouldWrap && !$element instanceof \Zend\Form\Element\Hidden && !$element instanceof \Zend\Form\Element\Button && $this->layout != Form::LAYOUT_BARE) {
             $elementString = sprintf('<div class="col-md-12">%s</div>', $elementString);
//.........这里部分代码省略.........
开发者ID:webpants,项目名称:YAWIK,代码行数:101,代码来源:FormRow.php

示例3: renderSummaryElement

 /**
  * Helper function to recurse into form elements when rendering summary.
  *
  * @param ElementInterface $element
  * @return string
  */
 protected function renderSummaryElement(ElementInterface $element)
 {
     if ($element instanceof Hidden || false === $element->getOption('render_summary')) {
         return '';
     }
     if ($element instanceof ViewPartialProviderInterface) {
         $renderer = $this->getView();
         /* @var $renderer \Zend\View\Renderer\PhpRenderer */
         $origPartial = $element->getViewPartial();
         $partial = "{$origPartial}.view";
         $partialParams = array('element' => $element);
         if (!$renderer->resolver($partial)) {
             $partial = $origPartial;
             $partialParams['renderSummary'] = true;
         }
         return $renderer->partial($partial, $partialParams);
     }
     if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) {
         /* @var $element EmptySummaryAwareInterface|ElementInterface */
         $emptySummaryNotice = $this->getTranslator()->translate($element->getEmptySummaryNotice(), $this->getTranslatorTextDomain());
         $markup = sprintf('<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', $element->getAttribute('id'), $emptySummaryNotice);
         return $markup;
     }
     $label = $this->getTranslator()->translate($element->getLabel());
     $markup = '';
     if ($element instanceof FieldsetInterface) {
         if (!$element instanceof FormInterface && $label) {
             $markup .= '<h4>' . $label . '</h4>';
         }
         foreach ($element as $el) {
             $markup .= $this->renderSummaryElement($el);
         }
         return $markup;
     }
     $elementValue = $element instanceof \Zend\Form\Element\Textarea ? nl2br($element->getValue()) : $element->getValue();
     if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) {
         $options = $element->getValueOptions();
         $translator = $this->getTranslator();
         if (true == $element->getAttribute('multiple')) {
             $multiOptions = [];
             foreach ($elementValue as $optionKey) {
                 if (isset($options[$optionKey])) {
                     $multiOptions['__general__'][] = $translator->translate($options[$optionKey]);
                     continue;
                 }
                 foreach ($options as $optKey => $optVal) {
                     if (!is_array($optVal) || !array_key_exists($optionKey, $optVal['options'])) {
                         continue;
                     }
                     $optGroupLabel = isset($optVal['label']) ? $translator->translate($optVal['label']) : $optKey;
                     $multiOptions[$optGroupLabel][] = $translator->translate($optVal['options'][$optionKey]);
                 }
             }
             $elementValue = [];
             foreach ($multiOptions as $optGroupLabel => $vals) {
                 $elementValue[] = "<b>{$optGroupLabel}</b><br>" . join(', ', $vals);
             }
             $elementValue = join('<br>', $elementValue) . '<br>';
         } else {
             $elementValue = $translator->translate($options[$elementValue]);
         }
     }
     if ('' != $elementValue && $element instanceof \Zend\Form\Element\File) {
         return '';
     }
     $markup .= '<div class="row">';
     $col = 12;
     if ($label) {
         $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>';
         $col = 9;
     }
     $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>';
     return $markup;
 }
开发者ID:utrenkner,项目名称:YAWIK,代码行数:80,代码来源:SummaryForm.php


注:本文中的Zend\Form\ElementInterface::getViewPartial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。