将类添加到围绕
我正在尝试
<div class="group wat-cf">
<div class="left">
<label class="label right">Username</label>
</div>
<div class="right">
<input type="text" class="text_field">
</div>
</div>
使用以下代码从 Zend_Form 中获取以下 html:
$username->setAttrib("class", "text_field")
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'div', 'class' => 'right')),
array('Label', array('tag' => 'div', 'class' => 'label right')),
array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
));
我可以获取下一个片段
<div class="group wat-cf">
<div id="username-label">
<label for="username" class="label right required">Username:</label>
</div>
<div class="right">
<input type="text" name="username" id="username" value="" class="text_field">
</div>
</div>
,因此除了一些额外的 id 和我不介意的所需类之外,我需要在 div id 上获取一个“left”类="username-label"
现在将类添加到标签行,获取添加到元素上的类。我也没有在标签装饰器代码本身中看到执行此操作的选项。所以我需要一个自定义标签装饰器,或者我缺少其他方法吗?
I'm trying to get the following html out of Zend_Form
<div class="group wat-cf">
<div class="left">
<label class="label right">Username</label>
</div>
<div class="right">
<input type="text" class="text_field">
</div>
</div>
Using the following code:
$username->setAttrib("class", "text_field")
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'div', 'class' => 'right')),
array('Label', array('tag' => 'div', 'class' => 'label right')),
array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
));
I can get the next fragment
<div class="group wat-cf">
<div id="username-label">
<label for="username" class="label right required">Username:</label>
</div>
<div class="right">
<input type="text" name="username" id="username" value="" class="text_field">
</div>
</div>
so apart from some extra id's and required classes i don't mind, i need to get a class "left" on div id="username-label"
Now adding class to the Label line, gets the class added on the element. I also don't see and option to do this in the Label decorator code itself. So i need a custom Label decorator, or is there some other way i'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在较新版本的 Zend 中,您可以添加
tagClass
参数。请参阅下面的“标签”数组
In newer versions of Zend you can add the
tagClass
parameter.See below in the "Label" array
这是一个很常见的问题。我认为,这个答案在这种情况下也可能有帮助:
添加一些html 到 Zend Forms
看一下 Padraic 的教程 以及。
This is pretty common question. I think, that this answer may by helpful in this case too:
Add some html to Zend Forms
Take look at Padraic's tutorial as well.