LoginSignup
5
5

More than 5 years have passed since last update.

SymfonyのFormで、任意のフィールドにマッピングする

Last updated at Posted at 2012-03-16

property_pathオプションを使う。falseでマッピングしない。

<?php

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class UserRegistrationType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            // usernameフィールドをemailプロパティにマッピング
            ->add('username', null, array('property_path' => 'email'))

            // 何も指定しないと同じ名前のプロパティにマッピング
            ->add('password', 'password')

            // falseを指定するとマッピングしない
            ->add('agreement', 'checkbox', array('property_path' => false))
        ;
    }
}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5