php – Zend Framework 2 – 表单元素装饰器
发布时间:2020-12-13 13:15:16 所属栏目:PHP教程 来源:网络整理
导读:我想强制Zend形式的Twitter Bootstrap风格.我现在遍历表单字段,并将表单信息写入我的bootstrap div构造. 我在Zend Framework 1(!)中看到,在装饰器中有一种方法可以做到这一点.但是由于某种原因,版本2的文档不涵盖这一点… 我想做这样的事情: protected $_f
我想强制Zend形式的Twitter Bootstrap风格.我现在遍历表单字段,并将表单信息写入我的bootstrap div构造.
我在Zend Framework 1(!)中看到,在装饰器中有一种方法可以做到这一点.但是由于某种原因,版本2的文档不涵盖这一点… 我想做这样的事情: protected $_format = '<label for="%s">%s</label>' . '<input id="%s" name="%s" type="text" value="%s"/>'; public function render($content) { $element = $this->getElement(); $name = htmlentities($element->getFullyQualifiedName()); $label = htmlentities($element->getLabel()); $id = htmlentities($element->getId()); $value = htmlentities($element->getValue()); $markup = sprintf($this->_format,$name,$label,$id,$value); return $markup; } 有任何想法吗?
我现在使用部分我正在迭代属性,构建一些例外,例如CSRF和Submit …这样做很顺利:
视图 echo $this->partial('partial/form-partial',array( 'form' => $this->form,'url' => $this->url('whatever',array('action' => 'add')))); ?> 局部 <?php $form = $this->form; $form->setAttribute ( 'action',$this->url () ); $form->prepare (); echo $this->form ()->openTag ( $form ); foreach ( $form as $element ) : ?> <div class="control-group <?php if($this->formElementErrors($element)) echo "error" ?>"> <label class="control-label"><?php echo $element->getLabel() ?></label> <div class="controls"> <?php echo $this->formElement ( $element ); if ($this->formElementErrors ( $element )) ?> <span class="help-inline"><?php echo $this->formElementErrors($element) ?></span> </div> </div> <?php endforeach; echo $this->form ()->closeTag ( $form ); ?> 这些例外是为了清楚的缘故而被排除在外 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |