簡體   English   中英

Symfony - Sonata 管理員 - 覆蓋驗證

[英]Symfony - Sonata admin - override validation

我正在使用奏鳴曲管理員,我試圖覆蓋類別名稱允許的最大長度

我有一個實體 MyEntity 擴展Application\Sonata\ClassificationBundle\Entity\Category

// MyEntity 管理員 class

我把這個放在 function 之后,關於https://sonata-project.org/bundles/core/master/doc/reference/conditional_validation.html#inline-validation

public function validate(\Sonata\Form\Validator\ErrorElement $errorElement, $object)
{
    parent::validate($errorElement, $object);

    $errorElement->with('name')
            ->assertLength(['max' => 100])
    ;
}

當前顯示

預計將在名稱字段上獲得 32 個最大長度

謝謝幫助

看起來您需要做的是覆蓋此驗證配置: https://github.com/sonata-project/SonataClassificationBundle/blob/3.x/src/Resources/config/validation.xml

<class name="Sonata\ClassificationBundle\Model\Category">
    <property name="name">
        <constraint name="NotBlank"/>
        <constraint name="Length">
            <option name="min">2</option>
            <option name="max">32</option>
        </constraint>
    </property>
</class>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM