如何向
// Doing this:
$e = new Zend_Form_Element_Select('combo');
$e->addMultiOptions(array(1=>'Jan',2=>'Feb'));
$e->renderViewHelper();
// I'll get something like this;
<select name="combo" id="combo">
<option value="1">Jan</option>
<option value="2">Feb</option>
</select>
如何使用 Zend Framework 向标签添加属性?
// I mean, I wanna get something like this:
<select name="combo" id="combo">
<option abc="123" value="1">Jan</option>
<option abc="456" value="2">Feb</option>
</select>
// Doing this:
$e = new Zend_Form_Element_Select('combo');
$e->addMultiOptions(array(1=>'Jan',2=>'Feb'));
$e->renderViewHelper();
// I'll get something like this;
<select name="combo" id="combo">
<option value="1">Jan</option>
<option value="2">Feb</option>
</select>
How could I add attributes to tags using Zend Framework?
// I mean, I wanna get something like this:
<select name="combo" id="combo">
<option abc="123" value="1">Jan</option>
<option abc="456" value="2">Feb</option>
</select>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你必须创建自己的类来扩展 Zend_Form_Element
I think you will have to create your own class extending Zend_Form_Element
为 Zend_Form_Element_Select 构建 HTML 的助手是 Zend_View_Helper_FormSelect。该助手在 _build 函数中构建元素。此函数仅创建具有以下属性的标签:
如果您想要更多选项,您需要使用自己的渲染助手创建自己的表单元素。我建议覆盖现有的并仅更改此特定部分。
亲切的问候,
罗宾
The helper that builds the HTML for the Zend_Form_Element_Select is Zend_View_Helper_FormSelect. This helper builds the elements in the _build function. This function only creates tags with the following attributes:
If you would like more options you would need to create your own form element with your own helper for rendering. I would suggest overriding the existing ones and just changing this specific part.
Kind regards,
Robin