您可以创建自定义行格式来定义字段将如何呈现(如果您还没有使用自定义模板)。我发现它在这forum thread。
一个很好的解决方案可能是压倒一切的formatRow
方法:
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
{
if(strip_tags($label) == '__UNSET__')
{
return strtr($this->getRowFormat(), array(
'%label%' => null,
'%field%' => $field,
'%error%' => $this->formatErrorsForRow($errors),
'%help%' => $this->formatHelp($help),
'%hidden_fields%' => is_null($hiddenFields) ? '%hidden_fields%' : $hiddenFields,
));
}
else
{
return strtr($this->getRowFormat(), array(
'%label%' => $label,
'%field%' => $field,
'%error%' => $this->formatErrorsForRow($errors),
'%help%' => $this->formatHelp($help),
'%hidden_fields%' => is_null($hiddenFields) ? '%hidden_fields%' : $hiddenFields,
));
}
}
然后,设置__UNSET__
为标签不应该有他们的标签渲染这些领域。
或者甚至根据标签名称使用自定义行格式以防止输出标签的封闭标签。
行格式看起来像这样<div >%field%%help%%error%%hidden_fields%</div>
,并且会通过此代替$this->getRowFormat()
。
这是什么,我已经上面写的代码版本的两行... – TheHippo 2009-12-15 09:55:39
对不起我打算输入一个空格,如果你输入一个空字符串,它将不起作用(正如你已经知道的)。这样,它会渲染
,但这仍然呈现标签标签... – TheHippo 2009-12-15 18:44:04