自定义布局到sfWidgetFormDoctrineChoice禁用复选框 [英] Customizing layout to sfWidgetFormDoctrineChoice disable checkbox
问题描述
早上好,
在Symfony 1.4中,
我试着做这里解释的内容:将布局自定义为sfWidgetFormDoctrineChoice
但它不起作用。而不是添加缩略图,我只是想在输入之前隐藏< li>
,并且在某些情况下禁用/隐藏复选框输入,但显示标签无论如何。
当我添加不带参数的渲染器时,出现此错误:
sfWidgetFormMySelectCheckbox需要以下选项:'choices'。
以下是我的格式化程序代码: 现在我称之为形式: 感谢您的帮助! 所以基本上你需要渲染器对象从父窗口部件中获取选择。要做到这一点,你必须传递一个 请记住 Good morning, In Symfony 1.4, Here is my formatter code : And now the form where I call it : Thanks for your help ! According to the docs you have to pass the So basically you want the renderer object get the choices from the parent widget. To do that you have to pass a Remember also that the 这篇关于自定义布局到sfWidgetFormDoctrineChoice禁用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p $公共函数配置($ options = array(),$ arguments = array())
{
父类: class sfWidgetFormMySelectCheckbox extends sfWidgetFormSelectCheckbox
{ :configure($ options,$ arguments);
}
受保护的函数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)),
);
}
返回call_user_func($ this-> getOption('formatter'),$ this,$ inputs);
}
}
$ this-> setWidget('aaa',new sfWidgetFormDoctrineChoice(array(
'模型'=>'aaa',
'expanded'=> true,
'multiple'=> true,
'add_empty'=> false,
' query'=> $ query,
'renderer'=> new sfWidgetFormMySelectCheckbox()
)));
选项
选项传递给渲染器
对象。尝试类似这样:
$ this-> setWidget('aaa',new sfWidgetFormDoctrineChoice(array(
'模型'=>'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
对象,该对象将一个数组
作为你传递实例的第一个参数您的父窗口小部件和函数名称 getChoices
。
当您覆盖
选项。 渲染器
时,不会使用扩展
I tried to do what is explained here : Customizing layout to sfWidgetFormDoctrineChoice
But it doesn't work. Instead of adding a thumbnail, I just want to hide the <li>
before the input, and in some condition disable/hide the checkbox input but show the label anyway.
When I add the renderer without argument, I get this error :
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
option to the renderer
object. Try something like this:$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
object which takes an array
as the first argument in which you pass the instance of your parent widget and the name of the function getChoices
.expanded
option is not used when you override the renderer
.