symfony - Symfony2 create new entity error: NotFoundException -


i getting notfoundhttpexception error when try create new entity form.

this code creating form , entity - categorycontroller:

 /**  * displays form create new category entity.  *  * @route("/new", name="category_new")  * @method({"get"})  */ public function newaction(request $request) {     $entity = new category();     $form   = $this->createcreateform($entity);       return array(         'entity' => $entity,         'form'   => $form->createview(),     ); }  /**  * creates new category entity.  *  * @route("/", name="category_create")  * @method("post")  * @template("adminbundle:categorypanel:new.html.twig")  */ public function createaction(request $request) {     $entity = new category();     $form = $this->createcreateform($entity);     $form->handlerequest($request);      if ($form->isvalid()) {         $em = $this->getdoctrine()->getmanager();          $em->persist($entity);         $em->flush();          return $this->redirect($this->generateurl('category_show', array('id' => $entity->getid())));     }      return array(         'entity' => $entity,         'form'   => $form->createview(),     ); }  /**  * creates form create category entity.  *  * @param category $entity  *  * @return \symfony\component\form\form form  */ private function createcreateform(category $entity, servicecategory $parentcategory = null) {     $form = $this->createform(categorytype::class, $entity, array(         'action' => $this->generateurl('category_create'),         'method' => 'post',         'parentcategory' => $parentcategory     ));      $form->add('submit', submittype::class, array(         'label' => 'create',         'attr' => array(             'class' => "btn btn-primary"         )     ));      return $form; } 

categorytype

      public function buildform(formbuilderinterface $builder, array $options) {     $builder->add('name', texttype::class, array('label' => 'category name'));      $parentcategory = $options["parentcategory"];      if($parentcategory != null){         $builder->add('parent', 'entity', array(             'class' => "corebundle:servicecategory",             'choices' => array($parentcategory)         ));     }else{         $builder->add('parent', 'entity', array(             'class' => "corebundle:servicecategory",             'query_builder' => function(servicecategoryrepository $cp){                 $qb = $cp->createquerybuilder('c');                 return $qb;             },         ));     }  } 

why code looking entity when attempting create it?

update

new.html.twig

{% extends 'adminbundle:adminpanel:base.html.twig' %}  {% block body -%} <h1>category creation</h1>  {{ form_start(form) }} {{ form_row(form.name) }} {{ form_row(form.parent) }}  <ul class="record_actions">     <li style="display: inline-block">         {{ form_widget(form.submit) }}     </li>     <li style="display: inline-block">         <a href="{{ path('category_panel_index') }}">             <button type="button" class="btn btn-primary">                 list             </button>         </a>     </li> </ul> {{ form_end(form) }} 

{% endblock %}

this might conflict between multiple routes happened in case.

you might have other route may in other controller having similar path (with dynamic varaibles) making <>/new pointing somewhere else.

please var_dump in newaction controller check if execution coming right there.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -