代码之家  ›  专栏  ›  技术社区  ›  Alex Pliutau

表中的Zend Form Decorators错误

  •  2
  • Alex Pliutau  · 技术社区  · 14 年前

    我正在使用next decorators作为我的输入。我想把这个做成桌子。

    $this->setDecorators(array('ViewHelper','Errors',
               array(array('data'=>'HtmlTag'), array('tag' => 'td')),
               array('Label', array('tag' => 'td')),
               array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
       ));
    

    但在表单验证后,td中没有显示错误。我该怎么做? 我想做下一个妆:

    <table>
       <tr>
          <td>Lable</td>
          <td>Input</td>
          <td>Error</td>
       </tr>
    </table>
    
    2 回复  |  直到 7 年前
        1
  •  4
  •   rodrigo-silveira selftaught91    11 年前
    $this->setDecorators(
       array(
          'ViewHelper',
          array(
             array(
                'data'=>'HtmlTag'
             ),
             array(
                'tag' => 'td'
             )
          ),
          array(
             'Label', 
             array(
                'tag' => 'td'
             )
          ),
          array(
             'Errors', 
             array(
                'tag' => 'td'
             )
          ),
          array(
             array(
                'row'=>'HtmlTag'
             ),
             array(
                'tag'=>'tr'
             )
          )
       )
    );
    
        2
  •  2
  •   multitask landscape    13 年前

    class My_Form_Decorator_ErrorsHtmlTag 
        extends Zend_Form_Decorator_Label
    {
        protected $_placement = 'APPEND';
    
        public function render($content) {
            $element = $this->getElement();
            $view = $element->getView();
            if (null === $view) {
                return $content;
            }
    
            $separator = $this->getSeparator();
            $placement = $this->getPlacement();
            $tag = $this->getTag();
            $tagClass = $this->getTagClass();
            $id = $element->getId();
    
            $errors = $element->getMessages();
            if (!empty($errors)) {
                $errors = $view->formErrors($errors, $this->getOptions());
            } else {
                $errors = '';
            }
    
            if (null !== $tag) {
                $decorator = new Zend_Form_Decorator_HtmlTag();
                if (null !== $tagClass) {
                    $decorator->setOptions(array(
                        'tag' => $tag,
                        'id' => $id . '-errors',
                        'class' => $tagClass));
                } else {
                    $decorator->setOptions(array(
                        'tag' => $tag,
                        'id' => $id . '-errors'));
                }
                $errors = $decorator->render($errors);
            }
    
            switch ($placement) {
                case self::APPEND:
                    return $content . $separator . $errors;
                case self::PREPEND:
                    return $errors . $separator . $content;
            }
        }
    }
    

    然后将其用作(在类中派生自 Zend_Form

    $this->addPrefixPath('My_Form_Decorator', 'My/Form/Decorator/', 'decorator');    
    $element->setDecorators(array(
        'ViewHelper',
        array(array('td' => 'HtmlTag'), array('tag' => 'td')),
        array('Label', array('tag' => 'td')),
        array('ErrorsHtmlTag', array('tag' => 'td')),
        array(array('tr' => 'HtmlTag'), array('tag' => 'tr'))));