sfWidgetFormChoice rendered as an unordered list
I'm using symfony 1.4.3
Is there some way to render a sfWidgetFormChoice as an unordered list?
In the API there is an option called 'renderer_class' but I c开发者_高级运维an't find any documentation or example about it.
Thanks!
take a look at lib/vendor/symfony/lib/widget/sfWidgetFormSelect.class.php
for example. Basically, what you need to do is implement a class that extends sfWidgetFormChoiceBase
and write a method render()
therein. A minimal example would look like this:
<?php
class sfWidgetFormChoiceUnordered extends sfWidgetFormChoiceBase
{
public function render($name, $value = null, $attributes = array(), $errors = array())
{
$result = '<ul>'
$choices = $this->getChoices();
foreach ($choices as $choice) {
$result .= '<li>' . $choice . '</li>';
}
return $result .= '</ul>';
}
}
You can put this in /lib/widget/sfWidgetFormChoiceUnordered.class.php
. Then you need to set the renderer_class
option on the sfWidgetFormChoice
widget like you already found out. Set it to the name of the class we just wrote: sfWidgetFormChoiceUnordered
.
Example:
...
$this->addWidget('choice', new sfWidgetFormChoice(array(
'renderer_class' => 'sfWidgetFormChoiceUnordered'
));
...
For documentation on the arguments to render()
, check out the example class I posted above.
精彩评论