I’m having a problem with symfony2 when i’m trying to save the data from a form to my database with Doctrine.
Here is the error
array
500 Internal Server Error - InvalidArgumentException
When I expand the debug, the error seems to be on the $em->persist($user);
And here is my function:
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');
}
}
Any ideas how I could fix that?
Edit
Here is my PostType class
<?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';
}
}
Can you post the PostType class?
Are you using debug page? (/app_dev.php).
Edit
just add this: