1

Doctrineを使用してフォームからデータベースにデータを保存しようとすると、symfony2で問題が発生します。

これがエラーです

array
500 Internal Server Error - InvalidArgumentException

デバッグを展開すると、エラーは$ em-> persist($ user)にあるようです。

そして、これが私の機能です:

 public function saveAction() {
    $request = $this->getRequest();
    $form = $this->createForm(new PostType());

    if ($request->getMethod() == "POST") {
        $form->bindRequest($request);
        if ($form->isValid()) {

           // $user = new PostEntity();
            $user = $form->getData();
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($user);
            $em->flush();

            $this->user = $user;
     } else {
            return new Response('Erro dados invalido');
        }

    }else {
        return new Response('Erro post');
    }
}

どうすればそれを修正できるか考えていますか?

編集

これが私のPostTypeクラスです

<?php

namespace blog\PostBundle\Form;

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

class PostType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
    $builder
        ->add('title')
        ->add('description')
        ->add('date')
    ;
}

public function getName()
{
    return 'blog_postbundle_posttype';
}
}
4

1 に答える 1

0

PostTypeクラスを投稿できますか?

デバッグページを使用していますか?(/app_dev.php)。


編集

これを追加するだけです:

public function getDefaultOptions(array $options) {
    return array(
        'data_class' => 'blog\PostBundle\Entity\Post',
    );
}
于 2012-05-23T00:18:29.567 に答える