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


PHP ElementInterface::setYearAttributes方法代码示例

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


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

示例1: render

 public function render(ElementInterface $element, $isHorizontal = false, $labelColumns = 2)
 {
     $escapeHtmlHelper = $this->getEscapeHtmlHelper();
     $labelHelper = $this->getLabelHelper();
     $elementHelper = $this->getElementHelper();
     $elementErrorsHelper = $this->getElementErrorsHelper();
     $label = $element->getLabel();
     $inputErrorClass = $this->getInputErrorClass();
     if (isset($label) && '' !== $label) {
         // Translate the label
         if (null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
     }
     $type = $element->getAttribute('type');
     if ($element instanceof DateSelect) {
         $attrs = $element->getDayAttributes();
         $classAttributes = in_array('class', $attrs) ? $attrs['class'] . ' ' : '';
         $classAttributes = $classAttributes . 'form-control';
         $attrs['class'] = $classAttributes;
         $element->setDayAttributes($attrs);
         $attrs = $element->getMonthAttributes();
         $classAttributes = in_array('class', $attrs) ? $attrs['class'] . ' ' : '';
         $classAttributes = $classAttributes . 'form-control';
         $attrs['class'] = $classAttributes;
         $element->setMonthAttributes($attrs);
         $attrs = $element->getYearAttributes();
         $classAttributes = in_array('class', $attrs) ? $attrs['class'] . ' ' : '';
         $classAttributes = $classAttributes . 'form-control';
         $attrs['class'] = $classAttributes;
         $element->setYearAttributes($attrs);
     } elseif ($type != 'checkbox' && $type != 'submit' && $type != 'button' && $type != 'radio' && $type != 'file' && $type != 'multi_checkbox') {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . 'form-control';
         $element->setAttribute('class', $classAttributes);
     } elseif ($type == 'button' || $type == 'submit') {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . 'btn';
         $element->setAttribute('class', $classAttributes);
     }
     // Does this element have errors ?
     if (count($element->getMessages()) > 0 && !empty($inputErrorClass)) {
         $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
         $classAttributes = $classAttributes . $inputErrorClass;
         $element->setAttribute('class', $classAttributes);
     }
     if ($this->partial) {
         $vars = ['element' => $element, 'label' => $label, 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $this->labelPosition, 'renderErrors' => $this->renderErrors];
         return $this->view->render($this->partial, $vars);
     }
     $elementErrors = '';
     if ($this->renderErrors) {
         $elementErrors = $elementErrorsHelper->render($element, ['class' => 'text-danger']);
     }
     $elementString = $elementHelper->render($element);
     $addonAppend = $element->getOption('addon-append');
     $addonPrepend = $element->getOption('addon-prepend');
     if ($addonAppend !== null || $addonPrepend !== null) {
         $addonString = '<div class="input-group">';
         $addonString .= $this->addAddon($addonPrepend);
         $addonString .= $elementString;
         $addonString .= $this->addAddon($addonAppend);
         $addonString .= '</div>';
         $elementString = $addonString;
     }
     $elementString .= $this->getHelpBlock($element);
     // hidden elements do not need a <label> -https://github.com/zendframework/zf2/issues/5607
     if (isset($label) && '' !== $label && $type !== 'hidden') {
         $labelAttributes = [];
         if ($element instanceof LabelAwareInterface) {
             $labelAttributes = $element->getLabelAttributes();
         }
         if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
             $label = $escapeHtmlHelper($label);
         }
         if (empty($labelAttributes)) {
             $labelAttributes = $this->labelAttributes;
         }
         if (!$element->getAttribute('id') && $element->getName()) {
             $element->setAttribute('id', $element->getName());
         }
         if ($element->getAttribute('id')) {
             $labelAttributes['for'] = $element->getAttribute('id');
         }
         if ($isHorizontal) {
             $labelAttributes['class'] = ' control-label col-sm-' . $labelColumns;
             if ($element instanceof LabelAwareInterface) {
                 $element->setLabelAttributes(['class' => 'control-label col-sm-' . $labelColumns]);
             }
         } else {
             $labelAttributes['class'] = ' control-label';
             if ($element instanceof LabelAwareInterface) {
                 $element->setLabelAttributes(['class' => 'control-label']);
             }
         }
         // 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
         if (!$isHorizontal && ($type === 'multi_checkbox' || $type === 'radio' || $element instanceof MonthSelect && !$element instanceof DateSelect)) {
             $markup = sprintf('<fieldset class="radio"><legend>%s</legend>%s</fieldset>', $label, $elementString);
         } elseif ($type == 'checkbox') {
//.........这里部分代码省略.........
开发者ID:lafaiDev,项目名称:suive_com,代码行数:101,代码来源:FormRow.php


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