それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

symfonyのAdmin-generatorで作られるフォームの要素は名前が特殊

やべ。盲点だった。admin-generatorが作るフォームのname=""はphpの特殊名で配列を使ってる。これは・・・

Using Array Syntax for Form Fields

PHP allows you to use an array syntax for the form fields. When writing your own forms, or when using the ones generated by the Propel administration (see Chapter 14), you may end up with HTML code that looks like Listing 10-33.

Listing 10-33 - Form with Array Syntax

<label for="story[title]">Title:</label>
<input type="text" name="story[title]" id="story[title]" value="default value"
       size="45" />

Using the input name as is (with brackets) in a validation file will throw a parsed-induced error. The solution here is to replace square brackets [] with curly brackets {} in the fields section, as shown in Listing 10-34, and symfony will take care of the conversion of the names sent to the validators afterwards.

Listing 10-34 - Validation File for a Form with Array Syntax

fields:
  story{title}:
    required:     Yes

だそうだ。admin-generatorが使うフォームのname=MODEL_NAME[COL_NAME]になっていたので、validate/edit.ymlもそれに併せて名前を使わなくてはいけない

fileds:
  post{title}:
    required:
      msg: "title は必須です"

これで、admin-generator使ってもvalidationは出来る。あとでやり方をまとめておく。