i'm new in symfony2 , started simple project of symblog create crud of posts , comments, when created crud of comments gone fine, have persist, merge , remove posts , have error:
catchable fatal error: argument 1 passed noticiabundle\repository\noticiarepository::adicionar() must 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 , defined
controller persist function:
/** * @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()); } persist repository
public function adicionar(noticia $noticia) { $this->_em->persist($noticia); $this->_em->flush(); return true; } and 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'; } } anyone can me??
in repository defined adicionar, check use statement. need make refer actual model, not proxy.
Comments
Post a Comment