Zend <dt> <dd> decorators: what do I lose by removing them

孤街浪徒 提交于 2019-12-08 02:41:27

问题


This question is specific to Zend_Form. Zend_Form adds standard decorators such as <dd> <dt> <dl>. What do I lose if I were to remove them? Are they used by Zend_Form itself for error reporting or any other reason?


回答1:


They are solely for structuring the output of your Zend Form elements in a definition list. Whether your form renders errors is controlled through the Error Decorator.

See this series of articles by Matthew Weier O'Phinney:

  • The simplest Zend Form Decorator
  • How to layer Decorators
  • Rendering Zend Form Decorators individually
  • Creating composite elements

and Rob Allen's Zend_Form Tutorial:

  • http://akrabat.com/tutorial/simple-zend_form-example/



回答2:


1) It's simplest and maybe the best practice to change appearance of forms via CSS, not by markup (by writing your own decorators), at least, when you're not experienced-well programmer. By removing DdDt decorator, lots of possibilities of CSS, such as input fields/labels/error-lists positioning, coloring, indenting and so on are lost. For example, to <dt> or <dd> you can add own class in form initialization, which later can be styled, satisfying your specific needs.

See code:

$comment = $this->createElement('textarea','comment',array(
    'label'=>'Post a comment',
    'required'=>true
))
  ->setDecorators(array(
    'ViewHelper', 
    'label', 
    'Errors', 
    array(
       'HtmlTag', 
       array(
          'tag' => 'dd', 
          'class'=>'elevatedField'
       )
    ) 
 ))
; 

Now in CSS stylesheet in .elevatedField{} rule you may define specific look for this textarea field. Actually, this example is not for default DdDt decorator, but it's explaining well ways of utilizing <dd> tag. Almost the same is for default DdDt decorator.

Look here what can be achieved with only css: http://robertbasic.com/blog/styling-the-default-zend_form-layout/ And it's not a limit.

2) Semantics of html markup is lost too, which almost have no meaning, at least for today.

Also, DdDt are not used by Zend_Form itself for error reporting - there is another standard decorator named 'Errors' for this needs.




回答3:


$element->removeDecorator('DtDdWrapper');

OR $element->clearDecorators(); and setting your own decorator;



来源:https://stackoverflow.com/questions/3870955/zend-dt-dd-decorators-what-do-i-lose-by-removing-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!