簡體   English   中英

可捕獲的致命錯誤:symfony2

[英]Catchable Fatal Error: symfony2

我是symfony2的新手,並啟動了一個symblog的簡單項目來創建一堆帖子和評論,當我創建一堆評論時,一切都很好,但是現在我必須堅持,合並和刪除我的帖子,並且出現此錯誤:

可捕獲的致命錯誤:傳遞給NoticiaBundle \\ Repository \\ NoticiaRepository :: adicionar()的參數1必須是Proxies__CG __ \\ NoticiaBundle \\ Entity \\ Noticia的實例,已指定NoticiaBundle \\ Entity \\ Noticia的實例,在C:\\ Desenvolvimento \\ wamp \\ www中調用\\ myproject \\ src \\ NoticiaBundle \\ Controller \\ NoticiaController.php在第49行並已定義

控制器持續功能:

/**
 * @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';
    }
}

有人可以幫助我嗎?

在您定義了adicionar存儲庫中,檢查您的use聲明。 您需要使其引用實際模型,而不是代理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM