简体   繁体   English

在symfony 1.4中选中的特定复选框

[英]Specific checkboxes checked in symfony 1.4

I'm able to do the following for all checkboxes in a set (in an action): 我可以对一组中的所有复选框执行以下操作(在操作中):

$this->form->getWidget('some_form_field')->setAttribute('checked', 'checked');

... but I'm unable to set specific checkboxes to ticked on the basis of data returned from the db. ...但是我无法根据数据库返回的数据将特定的复选框设置为打勾。

I'm after something like: 我在追求类似的东西:

$this->form->getWidget('some_form_field')->setAttributes(array(....));

... where I can refer to the specific checkboxes to be ticked somehow, or pass an array to it. ...在这里我可以参考要以某种方式打勾的特定复选框,或将数组传递给它。

There's nothing in the symfony documentation on this specifically and I've had enough of trying a dozen combinations to get it work. symfony文档中对此没有任何具体说明,并且我已经尝试了许多组合以使其正常工作。

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks. 谢谢。

This sounds a bit unusual? 这听起来有点不寻常? Are you using the generated propel/doctrine forms? 您是否正在使用生成的推进/学说形式? They should handle it automatically. 他们应该自动处理它。

Either way, setting the checked attribute is not the correct way to achieve this. 无论哪种方式,设置checked属性都不是实现此目的的正确方法。 Better way is within the form (because as far as I remember, $this->widgetSchema is protected) to do: 更好的方法是在表单中执行(因为据我所知,$ this-> widgetSchema受保护):

$this->widgetSchema['some_form_field']->setDefault(array('value1', 'value2'));

That will then cause widgets with those values to be checked. 然后,这将导致检查具有这些值的小部件。

(if thats not right, I wrote it off the top of my head, I can dig some code out and check, so let me know!) (如果那是不对的,我就把它写在脑海上,我可以挖掘出一些代码进行检查,所以让我知道!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM