[英]Customizing layout to sfWidgetFormDoctrineChoice disable checkbox
早上好,
在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
选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.