将布局自定义为sfWidgetFormDoctrine选择禁用复选框



早上好,

在Symfony 1.4中,
我试着做这里解释的事情:自定义布局到sfWidgetFormDoctrineChoice
但它不起作用。与其添加缩略图,我只想在输入之前隐藏<li>,在某些情况下禁用/隐藏复选框输入,但无论如何都显示标签
添加不带参数的渲染器时,会出现以下错误:
sfWidgetFormMySelectCheckbox requires the following options: 'choices'.

这是我的格式化程序代码:

class sfWidgetFormMySelectCheckbox extends sfWidgetFormSelectCheckbox
{
  public function configure($options = array(), $arguments = array())
  {
    parent::configure($options, $arguments);
  }
  protected function formatChoices($name, $value, $choices, $attributes)
  {
    .....
      // new
      $inputs[$id] = array(
        'input' => sprintf('| test | %s',
          $this->renderTag('input', array_merge($baseAttributes, $attributes))
        ),
        'label' => $this->renderContentTag('label', self::escapeOnce($option), array('for' => $id)),
      );
    }
    return call_user_func($this->getOption('formatter'), $this, $inputs);
  }
}

现在我称之为:

$this->setWidget('aaa', new sfWidgetFormDoctrineChoice(array(
    'model' => 'Aaa',
    'expanded' => true,
    'multiple' => true,
    'add_empty' => false,
    'query' => $query,
    'renderer' => new sfWidgetFormMySelectCheckbox()
  )));

谢谢你的帮助!

根据文档,您必须将choices选项传递给renderer对象。试试这样的东西:

$this->setWidget('aaa', new sfWidgetFormDoctrineChoice(array(
    'model' => 'Aaa',
    'expanded' => true,
    'multiple' => true,
    'add_empty' => false,
    'query' => $query,
)));
$this->widgetSchema['aaa']->setOption('renderer', new sfWidgetFormMySelectCheckbox(array(
    'choices' => new sfCallable(array($this->widgetSchema['aaa'], 'getChoices'))
)));

因此,基本上,您希望渲染器对象从父窗口小部件中获得选择。要做到这一点,您必须传递一个sfCallable对象,该对象将array作为第一个参数,在该参数中传递父小部件的实例和函数getChoices的名称。

还要记住,当覆盖renderer时,不会使用expanded选项。

最新更新