

symfony3でお問い合せのページを作成しているのですが、DBに保存する際に、下記のエラーが出て原因が追求できません。

[code]

    *An exception occurred while executing 'INSERT INTO inquiry (name, email, tel, type, content) VALUES (?, ?, ?, ?, ?)' with params [null, null, null, null, null]:
    SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null*
    
[/code]

ソースは以下の通りです。

_・AppBundle/Controller/InquiryController.php_

[code]

    namespace AppBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
    use Symfony\Component\Form\Extension\Core\Type\TextareaType;
    use Symfony\Component\Form\Extension\Core\Type\SubmitType;
    use Symfony\Component\HttpFoundation\Request;
    use AppBundle\Entity\Inquiry;
    use AppBundle\Repository\UnseiRepository;
    
    /**
     * @Route("/inquiry")
     */
    class InquiryController extends Controller{
        /**
         * @Route("/")
         * @Method("get")
         */
        public function indexAction(){
            return $this->render('Inquiry/index.html.twig',
                ['form'=> $this->createInquiryForm()->createView()]
            );
        }
        public function createInquiryForm(){
            return $this->createFormBuilder()
            ->add('name',TextType::class)
            ->add('email',TextType::class)
            ->add('tel',TextType::class,[
                'required'=> false,
            ])
            ->add('type',ChoiceType::class,[
                'choices' => [
                    '公演について',
                    'その他',
                ],
                'expanded' => true,
            ])
            ->add('content',TextareaType::class)
            ->add('submit',SubmitType::class,[
                'label' => '送信',
            ])
            ->getForm();
        }
    
        /**
         * @Route("/")
         * @Method("post")
         */
        public function indexPostAction(Request $request){
            $inquiry = new Inquiry();
            $form = $this->createInquiryForm(Register::class, $inquiry);
            $form->handleRequest($request);
    
    
            if($form->isValid()){
                $data = $form->getData();
    
                //POSTデータをDBに保存
                $inquiry = new Inquiry();
                $inquiry->setName($data["name"]);
                $inquiry->setEmail($data["email"]);
                $inquiry->setTel($data["tel"]);
                $inquiry->setType($data["type"]);
                $inquiry->setContent($data["content"]);
    
                $em = $this->getDoctrine()->getManager();
                $em->persist($inquiry);
                $em->flush();
    
                $message = \ Swift_Message::newInstance()
                    ->setSubject("Webサイトからのお問い合わせ")
                    ->setFrom('@gmail.com')
                    ->setTo('@yahoo.co.jp')
                    ->setBody(
                        $this->renderView(
                            'mail/inquiry.txt.twig',
                            ['data'=>'$data']
                        )
                    );
                $this->get('mailer')->send($message);
    
                return $this->render('Inquiry/complete.html.twig');
            }
            return $this->render('Inquiry/index.html.twig',['form'=> $form->createView()]);
        }
    
        /**
         * @Route("/complete")
         */
        public function completeAction(){
            return $this->render('Inquiry/complete.html.twig');
        }
    }
    
[/code]

_・AppBundle/Entity/Inquiry.php_

[code]

    namespace AppBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * Inquiry
     *
     * @ORM\Table(name="inquiry")
     * @ORM\Entity(repositoryClass="AppBundle\Repository\InquiryRepository")
     */
    class Inquiry
    {
        /**
         * @var int
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
         private $id;
    
         /**
          * @var string
          *
          * @ORM\Column(name="name", type="string", length=30)
          *
          *
          */
         private $name;
    
         /**
          * @var string
          *
          * @ORM\Column(name="email", type="string", length=100)
          *
          *
          */
         private $email;
    
         /**
          * @var string
          *
          * @ORM\Column(name="tel", type="string", length=20, nullable=true)
          *
          *
          */
         private $tel;
    
         /**
          * @var string
          *
          * @ORM\Column(name="type", type="string", length=20)
          *
          *
          */
         private $type;
    
        /**
         * @var string
         *
         * @ORM\Column(name="content", type="text")
         *
         *
         */
        private $content;
    
        /**
         * Get id
         *
         * @return int
         */
        public function getId()
        {
            return $this->id;
        }
    
        /**
         * Set tel
         *
         * @return varchar
         */
        public function setTel()
        {
            return $this->tel;
        }
    
        /**
         * Set name
         *
         * @return varchar
         */
        public function setName()
        {
            return $this->name;
        }
    
        /**
         * Set email
         *
         * @return varchar
         */
        public function setEmail()
        {
            return $this->email;
        }
    
        /**
         * Set type
         *
         * @return varchar
         */
        public function setType()
        {
            return $this->type;
        }
    
        /**
         * Set content
         *
         * @return varchar
         */
        public function setContent()
        {
            return $this->content;
        }
    
    
       /**
        * Get name
        *
        * @return string
        */
       public function getName()
       {
            return $this->name;
       }
    
       /**
        * Get email
        *
        * @return string
        */
       public function getEmail()
       {
           return $this->email;
       }
    
       /**
        * Get tel
        *
        * @return string
        */
       public function getTel()
       {
           return $this->tel;
       }
    
      /**
       * Get type
       *
       * @return string
       */
      public function getType()
      {
          return $this->type;
      }
    
      /**
       * Get content
       *
       * @return string
       */
      public function getContent()
      {
          return $this->content;
      }
    }
    
[/code]

Controllerの以下の時点で各$dataのvalueがnullになることを確認しており、上記エラーメッセージが出るのだと思いますが、何故valueがnullになるのか原因が分かりません。

[code]

    $inquiry = new Inquiry();
    $inquiry->setName($data["name"]);
    $inquiry->setEmail($data["email"]);
    $inquiry->setTel($data["tel"]);
    $inquiry->setType($data["type"]);
    $inquiry->setContent($data["content"]);
    
[/code]

また、Entityで以下のように引数もセットして試したましたが、エラーは解消しませんでした。  
どなたか原因がわかる方、ご教示願います。

[code]

    public function setTel($tel)
    {
        return $this->tel;
    }
    
[/code]


CC BY-SA 4.0
2018-05-06T18:19:55.417
43827
2018-05-06T21:19:18.833
2018-05-06T21:19:18.833
3068
28436
question
symfony2
Symfony3のDBの保存について