简体   繁体   English

Sonata Admin type_collection和级联验证

[英]Sonata Admin type_collection & cascade validation

I am having a problem with implementing the one to many relationship in the sonata admin with the following structure. 我在使用以下结构在sonata admin中实现一对多关系时遇到问题。

->add('adhesions', 'sonata_type_collection', array('by_reference' => false,'required' => false), array(
    'edit' => 'inline',
    'inline' => 'table',
    'sortable'  => 'position',))

With this option : 'edit' => 'inline', i lost default validation defined in AdhesionAdmin like 'required' => true. 使用此选项:'edit'=>'inline',我丢失了AdhesionAdmin中定义的默认验证,如'required'=> true。

So, is there a setting to specify somewhere ? 那么,是否有指定某处的设置? I tried to add 'cascade_validation' => true in settings of the sonata_type_collection but it has not changed. 我试图在sonata_type_collection的设置中添加'cascade_validation'=> true但它没有改变。

Another question: can I use popup edit form with the sonata_type_collection ? 另一个问题:我可以使用带有sonata_type_collection的弹出编辑表单吗? ('edit' => 'standard') ('edit'=>'标准')

Any pointers and help is highly appreciated. 任何指针和帮助都非常感谢。 Thank you 谢谢

You have to enable cascade_validation. 您必须启用cascade_validation。 You can do it this way: 你可以这样做:

  class UserAdmin extends SonataUserAdmin  
  {    
     protected $formOptions = array(
        'cascade_validation' => true        
     );

     /* Rest of your admin class code */


  }

Just use Valid constraint on your entity property instead: 只需在您的实体属性上使用Valid约束:

/**
 * @var Object[]
 *
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\Object", mappedBy="myEntity")
 * @Assert\Valid
 */
private $objects;

http://symfony.com/doc/current/reference/forms/types/collection.html#cascade-validation http://symfony.com/doc/current/reference/forms/types/collection.html#cascade-validation

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

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