如何更改 symfony 中 sfWidgetFormSelectRadio 的行为?
new sfWidgetFormSelectRadio(
array('choices' => $images)));
上面将渲染每个选项,如下所示:
<input type="radio" name="name" value="image_path">
如何使用最少的代码使其以这种方式渲染:
<input type="radio" name="name" value="image_path"><img src="image_path" />
new sfWidgetFormSelectRadio(
array('choices' => $images)));
The above will render each option something like:
<input type="radio" name="name" value="image_path">
How to make it render this way with minimal code:
<input type="radio" name="name" value="image_path"><img src="image_path" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是未经测试的,是我直接阅读 Symfony API 文档
像这样重写
formatChoices()
方法:这样您基本上就将
img
标记附加到输入中。在表单的
configure()
方法中,您需要从使用sfWidgetFormSelectRadio
切换到使用myWidgetFormSelectRadio
才能使用新的小部件。让我知道这是否有效;-)
This is untested and straight from me reading the Symfony API docs for that widget. You'll need to extend the
sfWidgetFormSelectRadio
class, call it something likemyWidgetFormSelectRadio
and stick it inlib/widget/myWidgetFormSelectRadio.class.php
in your project.Override the
formatChoices()
method like so:so you're basically appending the
img
tag to the input.In your form's
configure()
method you'll then need to switch from usingsfWidgetFormSelectRadio
to usingmyWidgetFormSelectRadio
to use the new widget.Let me know if this works ;-)