自定义布局sfWidgetFormDoctrineChoice禁用复选框(Customizing l

2019-10-19 01:15发布

早上好,

在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()
  )));

谢谢你的帮助 !

Answer 1:

根据该文件,你必须通过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

也请记住, expanded ,当你覆盖选项不能用于renderer



文章来源: Customizing layout to sfWidgetFormDoctrineChoice disable checkbox