问题
I'm using DisplayGroup to render a couple of elements in a group. Now what I want to do, is render this group in a single table row. But it turns out, that Decorators on DisplayGroups do NOT work the same way they do on simple elements. An example:
$content = $this->getDisplayGroup('group');
$content->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'table', 'class' => 'element')),
));
This just puts
<table></table> at the end of my DisplayGroup. I've also tried to alias them:
array(array('elementDiv' => 'HtmlTag'), array('tag' => 'table')),
'FormElements',
array(array('td' => 'HtmlTag'), array('tag' => 'table')),
Still puts them in one place, not both tried openOnly and closeOnly :
array(array('elementDiv' => 'HtmlTag'), array('tag' => 'table','openOnly'=>true)),
'FormElements',
array(array('td' => 'HtmlTag'), array('tag' => 'table','closeOnly'=>true)),
And it still puts in only the closing tag. If I change these to <td>, everything works fine, but not with <table> Am I missing something?
回答1:
So, jah was right, and the table not being added was really a bug of source viewers.
$group->setDecorators(array(
'FormElements',
array('Description', array('escape' => false, 'tag' => false)),
array('HtmlTag', array('tag' => 'table', 'class' => 'element')),
));
This did the trick for me. Not really sure what the Description Decorator does, but the table renders as needed.
来源:https://stackoverflow.com/questions/4315967/displaygroup-decorator-in-zend-framework