sfWidgetFormChoice rendered as an unordered list

孤街浪徒 提交于 2019-12-06 11:56:09

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!