我是symfony2中的新成員,並開始了一個簡單的symblog項目,以創建一個帖子和評論,當我創建一個評論的一切糟糕的一切都很好,但現在我必須堅持,合併和刪除我的帖子,我有此錯誤:可捕捉的致命錯誤:symfony2
Catchable Fatal Error: Argument 1 passed to NoticiaBundle\Repository\NoticiaRepository::adicionar() must be an instance of Proxies__CG__\NoticiaBundle\Entity\Noticia, instance of NoticiaBundle\Entity\Noticia given, called in C:\Desenvolvimento\wamp\www\myproject\src\NoticiaBundle\Controller\NoticiaController.php on line 49 and defined
控制器堅持功能:
/**
* @Route("/cadastrar_noticia", name="_cadastrar_noticia")
* @Template()
*/
public function cadastrarAction() {
$noticia = new Noticia();
$request = $this->getRequest();
$form = $this->createForm(new NoticiaType(), $noticia);
$form->handleRequest($request);
if ($form->isValid()) {
try {
$noticia = $form->getData();
$noticiaRepository = $this->getDoctrine()->getRepository('NoticiaBundle:Noticia');
$noticiaRepository->adicionar($noticia);
$this->addFlash('success', 'Noticia cadastrada com sucesso');
return $this->redirectToRoute('_imagem_raias_index');
} catch (Exception $ex) {
echo $ex->getMessage();
}
}
return array("form" => $form->createView());
}
堅持倉庫
public function adicionar(Noticia $noticia) {
$this->_em->persist($noticia);
$this->_em->flush();
return true;
}
而我的FormType
<?php
namespace NoticiaBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class NoticiaType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('titulo',null, array('attr' => array('class' => 'form-control'),
'label_attr' => array('class' => 'control-label col-lg-2')
))
->add('imagem',null, array('attr' => array('class' => 'form-control'),
'label_attr' => array('class' => 'control-label col-lg-2')
))
->add('noticia','textarea', array('attr' => array('class' => 'form-control', 'rows' => 15),
'label_attr' => array('class' => 'control-label col-lg-2')
))
->add('tags',null, array('attr' => array('class' => 'form-control'),
'label_attr' => array('class' => 'control-label col-lg-2')
))
->add('salvar', 'submit', array('attr' => array('class' => 'btn btn-primary pull-right')));
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'NoticiaBundle\Entity\Noticia'
));
}
/**
* @return string
*/
public function getName()
{
return 'noticiabundle_noticia';
}
}
任何人都可以幫助我?