简体   繁体   English

我的Symfony2项目上的路由问题

[英]Issue with routing on my Symfony2 project

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. 在模板的渲染过程中,在第38行的“ CasanetBundle:Admin:deliverables.html.twig”中渲染了一个模板(“由于该路由不存在,因此无法为命名路由“ casanet_addpaperpage”生成URL”。)

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: 这是我的routing.yml文件中的相关路由:

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. 由于您的路由位于router:debug --env = dev中,因此您可能只需要清除缓存。

 php app/console cache:clear --env=dev

or prod if you use prod. 或prod(如果您使用prod)。

I found out what was wrong. 我发现了问题所在。

I ran a composer no-dev update and interrupted it 1 day ago, and it corrupted. 我运行了作曲家的no-dev更新,并在1天前中断了它,但它已损坏。 Today I updated to Symfony 2.6.5 and it solved the issue I suppose. 今天,我更新到了Symfony 2.6.5,它解决了我想的问题。 Thanks everyone! 感谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM