搜尋

首頁  >  問答  >  主體

symfony - 如何將下面的註解改成yml?

雷雷
世界只因有你世界只因有你2804 天前433

全部回覆(1)我來回復

  • 滿天的星座

    滿天的星座2017-05-16 16:46:02

    你的 Annotations 註解包含兩個部分,實體欄位 (Column) 和 驗證規則 (Assert),在 Symfony 中需要分別定義到兩個 Yml 檔案中。

    實體欄位:

    http://symfony.com/doc/current/book/doctrine.html

    // src/AppBundle/Resources/onfig/doctrine/EntityName.orm.yml
    
    AppBundle\Entity\EntityName:
        type: entity
        table: tableName
        // ...
        fields:
            name:
                type: string
                length: 255

    驗證規則:

    http://symfony.com/doc/current/book/validation.html

    // src/AppBundle/Resources/config/validation.yml
    
    AppBundle\Entity\EntityName:
        properties:
            name:
                - NotBlank: { message: "Please enter your name.", groups: [Registration, Profile] }
                - MinLength: { limit: 3, message: "The name is too short.", groups: [Registration, Profile] }
                - MaxLength: { limit: 255, message: "The name is too long.", groups: [Registration, Profile] }

    回覆
    0
  • 取消回覆