Symfony embedRelation 选项 - 设置子表单字段可见性
embedRelation 的原型引用“options”数组(作为 $formArguments/$formargs 传递)。
是否可以传递一个选项数组:
embedRelation("Model","ModelForm",$options_arr);
其中 options_arr 包含表单验证器/小部件/等来设置关系?
$formargs['something']['publish_date'] = new sfWidgetFormInputText();
或者是否可以以这样的方式限制为关系显示的表单字段?
$formargs['something']['use_fields'] = array('publish_date');
来自 sfFormDoctrine.class.php ...
* Embed a Doctrine_Collection relationship in to a form
*
* [php]
* $userForm = new UserForm($user);
* $userForm->embedRelation('Groups AS groups');
*
* @param string $relationName The name of the relation and an optional alias
* @param string $formClass The name of the form class to use
* @param array $formArguments Arguments to pass to the constructor (related object will be shifted onto the front)
* @param string $innerDecorator A HTML decorator for each embedded form
* @param string $decorator A HTML decorator for the main embedded form
*
* @throws InvalidArgumentException If the relationship is not a collection
*/
public function embedRelation($relationName, $formClass = null, $formArgs = array(), $innerDecorator = null, $decorator = null)
...
我能够获得的最接近 $formArgs array() 的规范来自 sfFormPropel.class.php (我正在使用原则 1.2):
* `title`: The title of the collection form once embedded. Defaults to the relation name.
* `embedded_form_class`: The class name of the forms to embed. Uses the model name by default (a form based on a collection of Book objects embeds BookForm objects).
* `collection_form_class`: Class of the collection form to return. Defaults to sfFormPropelCollection.
* `hide_on_new`: If true, the relation form does not appear for new objects. Defaults to false.
* `add_empty`: Whether to allow the user to add new objects to the collection. Defaults to true.
* `add_delete`: Whether to add a delete widget for each object. Defaults to true.
* `remove_fields`: The list of fields to remove from the embedded object forms
* `item_pattern`: The pattern used to name each embedded form. Defaults to '%index%'.
If `add_empty` is set to `true`, the following additional options are available:
* `empty_label`: The label of the empty form. Defaults to 'new' + the relation name.
* `add_link`: The text of the JavaScript link that displays the empty form. Defaults to `Ann new`
* `max_additions`: The max number of additions accepted on the client side. Defaults to 0 (no limit)
If `add_delete` is set to `true`, the following additional options are available:
* `delete_name`: Name of the delete widget. Defaults to 'delete'.
* `delete_widget`: Optional delete widget object. If left null, uses a `sfWidgetFormDelete` instance, which is a checkbox widget with a Javascript confirmation.
* `alert_text`: The text of the Javascript alert to show.
* `hide_parent`: Whether to hide the deleted form when clicking the checkbox. Defaults to true.
* `parent_level`: The number of times parentNode must be called to reach the parent to hide. As a widget doesn't know if it's merged or embedded, this setting allows the JavaScript code used to hide the parent to find it. Recommended values: 6 for embedded form (default), 7 for merged form.
任何见解将不胜感激。
The prototype of embedRelation makes reference to an 'options' array (passed as $formArguments/$formargs).
Is it possible to pass an options array:
embedRelation("Model","ModelForm",$options_arr);
Where the options_arr contains form validator/widgets/etc to set for the relation?
$formargs['something']['publish_date'] = new sfWidgetFormInputText();
Or is it possible to limit the form fields displayed for a relation in a way like this?
$formargs['something']['use_fields'] = array('publish_date');
From sfFormDoctrine.class.php
...
* Embed a Doctrine_Collection relationship in to a form
*
* [php]
* $userForm = new UserForm($user);
* $userForm->embedRelation('Groups AS groups');
*
* @param string $relationName The name of the relation and an optional alias
* @param string $formClass The name of the form class to use
* @param array $formArguments Arguments to pass to the constructor (related object will be shifted onto the front)
* @param string $innerDecorator A HTML decorator for each embedded form
* @param string $decorator A HTML decorator for the main embedded form
*
* @throws InvalidArgumentException If the relationship is not a collection
*/
public function embedRelation($relationName, $formClass = null, $formArgs = array(), $innerDecorator = null, $decorator = null)
...
The closest I've been able to get to a spec for the $formArgs array() is from sfFormPropel.class.php (I'm using doctrine 1.2):
* `title`: The title of the collection form once embedded. Defaults to the relation name.
* `embedded_form_class`: The class name of the forms to embed. Uses the model name by default (a form based on a collection of Book objects embeds BookForm objects).
* `collection_form_class`: Class of the collection form to return. Defaults to sfFormPropelCollection.
* `hide_on_new`: If true, the relation form does not appear for new objects. Defaults to false.
* `add_empty`: Whether to allow the user to add new objects to the collection. Defaults to true.
* `add_delete`: Whether to add a delete widget for each object. Defaults to true.
* `remove_fields`: The list of fields to remove from the embedded object forms
* `item_pattern`: The pattern used to name each embedded form. Defaults to '%index%'.
If `add_empty` is set to `true`, the following additional options are available:
* `empty_label`: The label of the empty form. Defaults to 'new' + the relation name.
* `add_link`: The text of the JavaScript link that displays the empty form. Defaults to `Ann new`
* `max_additions`: The max number of additions accepted on the client side. Defaults to 0 (no limit)
If `add_delete` is set to `true`, the following additional options are available:
* `delete_name`: Name of the delete widget. Defaults to 'delete'.
* `delete_widget`: Optional delete widget object. If left null, uses a `sfWidgetFormDelete` instance, which is a checkbox widget with a Javascript confirmation.
* `alert_text`: The text of the Javascript alert to show.
* `hide_parent`: Whether to hide the deleted form when clicking the checkbox. Defaults to true.
* `parent_level`: The number of times parentNode must be called to reach the parent to hide. As a widget doesn't know if it's merged or embedded, this setting allows the JavaScript code used to hide the parent to find it. Recommended values: 6 for embedded form (default), 7 for merged form.
Any insight would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为,如果您将
array('toto' => 'pwet')
作为表单参数,您将能够使用$this-> 在表单中检索 'pwet' ;getOption('toto');
从那里一切皆有可能(设置小部件和验证器)I think that if you put say
array('toto' => 'pwet')
as form args, you will be able to retrieve 'pwet' in your form using$this->getOption('toto');
From there everything is possible (setting widgets and validators)你为什么不走另一条路:
Why don't you go another way: