简体   繁体   English

奏鸣曲管理员验证

[英]Sonata Admin validation

I have an trouble with validation in Sonata Admin.我在 Sonata Admin 中进行验证时遇到问题。

On frontend for clients I have two forms: Registration and ProfileEdit.在客户端的前端,我有两种形式:注册和配置文件编辑。 Based on FOSUser.基于 FOSUser。 Rules for validation are in:验证规则在:

src/UserBundle/Resources/config/validation.yml src/UserBundle/Resources/config/validation.yml

There are two groups of validation for each form.每个表单有两组验证。 For me is preferable in backend to use this rules and add one more group like AdminProfileEdit because there are diffences with frontend forms.对我来说,最好在后端使用此规则并添加一个像 AdminProfileEdit 这样的组,因为前端表单存在差异。 But, I cannot understand how to config?但是,我不明白如何配置? In docs I read about inlineValidation - add in UserAdmin class a method在文档中,我阅读了有关 inlineValidation - 在 UserAdmin 类中添加一个方法

/**
 * @param ErrorElement $errorElement
 * @param mixed $object
 */
public function validate(ErrorElement $errorElement, $object)
{
    $errorElement
        ->with('profile.firstname')
            ->assertNotBlank()
        ->end()
        ....
    ;
}

but for me it is bad solution to have 2 validation configs.但对我来说,有 2 个验证配置是不好的解决方案。 In https://sonata-project.org/bundles/admin/2-0/doc/reference/conditional_validation.html I can not find a good explanation how to validate a backend form.https://sonata-project.org/bundles/admin/2-0/doc/reference/conditional_validation.html我找不到如何验证后端表单的好解释。

In Sonata\\AdminBundle\\Admin\\AdminInterface method validate is marked as deprecated:在 Sonata\\AdminBundle\\Admin\\AdminInterface 方法验证被标记为已弃用:

  • @deprecated this feature cannot be stable, use a custom validator, @deprecated 此功能不稳定,请使用自定义验证器,
  • the feature will be removed with Symfony 2.2该功能将在 Symfony 2.2 中删除

what it mean?什么意思? And how to validate?以及如何验证? Can someone write step-by-step what to do?有人可以一步一步写出该怎么做吗? Even what methods or configs I need to have?甚至我需要什么方法或配置?

Please help someone, I need to make task fastly, and donn't have plan or solution.请帮助某人,我需要快速完成任务,并且没有计划或解决方案。

You can define a validation group for the admin and specify it as a form option in the admin class :您可以为管理员定义一个验证组,并将其指定为admin 类中表单选项

protected $formOptions = array(
    'validation_groups' => array('SomeGroup'),
);

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

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