I'm facing the following error:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "casanet_addpaperpage" as such route does not exist.") in "CasanetBundle:Admin:deliverables.html.twig" at line 38.
Here is my Controller:
<?php
namespace ProjectB\CasanetBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use ProjectB\CasanetBundle\Entity\Paper;
use ProjectB\CasanetBundle\Entity\Event;
use ProjectB\CasanetBundle\Entity\Conference;
use ProjectB\CasanetBundle\Entity\Project;
use ProjectB\CasanetBundle\Form\PaperType;
class AdminController extends Controller {
public function deliverablesAction() {
$em = $this->getDoctrine()->getManager();
$papers = $em->getRepository("CasanetBundle:Paper")->findAll();
$events = $em->getRepository("CasanetBundle:Event")->findAll();
$conferences = $em->getRepository("CasanetBundle:Conference")->findAll();
$projects = $em->getRepository("CasanetBundle:Project")->findAll();
return $this->render('CasanetBundle:Admin:deliverables.html.twig', array(
"papers" => $papers,
"events" => $events,
"conferences" => $conferences,
"projects" => $projects,
));
}
public function addpaperAction(Request $request){
$paper = new Paper();
$formPaper = $this->createForm(new PaperType(), $paper);
if($request->isMethod("POST")){
$formPaper->handleRequest($request);
if($formPaper->isValid()){
$em = $this->getDoctrine()->getManager();
$paper = $formPaper->getData();
$em->persist($paper);
$em->flush();
}
return $this->redirectToRoute("casanet_deliverablespage");
}
return $this->render('CasanetBundle:Admin:addpaper.html.twig', array(
"formPaper" => $formPaper->createView(),
));
}
}
Here is the concerned route in my routing.yml file:
casanet_addpaperpage:
path: /admin/addpaper
defaults: { _controller: CasanetBundle:Admin:addpaper }
I've tried clearing the cache, running composer updates,renaming the route, routing through other paths, and so far no results.
Can anyone hint me towards the right way?
EDIT: Here's the concerned segment of my view:
<a href="{{path("casanet_addpaperpage") }}" class="btn btn-primary">Add a paper</a>
Think it's because your shortname for your bundle isn't right, should be
casanet_addpaperpage:
path: /admin/addpaper
defaults: { _controller: ProjectBCasanetBundle:Admin:addpaper }
Since your route is present in router:debug --env=dev then you probably just need to clear the cache.
php app/console cache:clear --env=dev
or prod if you use prod.
I found out what was wrong.
I ran a composer no-dev update and interrupted it 1 day ago, and it corrupted. Today I updated to Symfony 2.6.5 and it solved the issue I suppose. Thanks everyone!