2012-05-22 5 views
1

Doctrine을 사용하여 양식의 데이터를 저장할 때 심포니 2에 문제가 있습니다. 여기 Symfony2는 저장시 오류가 발생합니다.

내가 디버그를 확장하면

array 
500 Internal Server Error - InvalidArgumentException 

이 오류가 $ 보하기> 지속 ($ 사용자)에있을 것 같다 오류입니다;

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'; 
} 
} 

답변

0

당신은 PostType 클래스를 게시 할 수 있습니까?

디버그 페이지를 사용하고 있습니까? (/app_dev.php).


편집

그냥이 추가 :

public function getDefaultOptions(array $options) { 
    return array(
     'data_class' => 'blog\PostBundle\Entity\Post', 
    ); 
} 
+0

이 홍보 PostType 클래스 입니다' ('제목')를 추가 - -> ('설명')를 추가 -> 추가 (' 클래스 PostType는 AbstractType { 공공 기능 buildForm (FormBuilder $ 빌더, 배열 $ 옵션) { $ 빌더 확장 날짜 ') ; } 공개 함수 getName() { 반환 'blog_postbundle_posttype'; } } –

+0

유형에 엔티티를 설정해야합니다. 답변을 확인하십시오. 나는 거기에 덧붙였다. –

관련 문제