dsieyx2015 2015-10-23 13:47
浏览 6
已采纳

在Sonata Admin中出现故障时,可以获得更详细的消息

I am curious about the way in which Sonata Admin handle and displays error messages as I need them to be a little more descriptive. For instance when the message comes from DB because a constraint fails I got a message like this:

An error has occurred during update of item "Media Title Test".

But if I leave a required field empty the error is the same. I want to know if it's possible to handle this in some way in order to be more descriptive. Any advice or help?

  • 写回答

1条回答 默认 最新

  • duanhuizhe6767 2015-10-23 14:22
    关注

    You can pass validation rules and message using Constraint in your entity.

    // src/AppBundle/Entity/Author.php
    
    // ...
    use Symfony\Component\Validator\Constraints as Assert;
    
    class Author
    {
        /**
         * @Assert\Choice(
         *     choices = { "male", "female", "other" },
         *     message = "Choose a valid gender."
         * )
         */
        public $gender;
    
        // ...
    }
    

    Validation Constraints Reference will give you a full list of constraint available by default in Symfony.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'