在我的Symfony2项目上路由问题

时间:2015-03-17 17:34:15

标签: php symfony routing twig

我遇到以下错误:

  

在呈现模板期间抛出异常(“无法生成指定路由的URL”casanet_addpaperpage“因为此类路由不存在。”)在“CasanetBundle:Admin:deliverables.html.twig”中第38行。

这是我的控制器:

<?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(), 
    ));

}
}       

以下是我的routing.yml文件中的相关路线:

casanet_addpaperpage:
    path:     /admin/addpaper
    defaults: { _controller: CasanetBundle:Admin:addpaper }

我尝试清除缓存,运行编辑器更新,重命名路由,通过其他路径路由,到目前为止没有结果。

有人能以正确的方式暗示我吗?

编辑:以下是我的观点的相关部分:

<a href="{{path("casanet_addpaperpage") }}" class="btn btn-primary">Add a paper</a>

3 个答案:

答案 0 :(得分:0)

认为这是因为您的捆绑包的短名称不对,应该是

casanet_addpaperpage:
    path:     /admin/addpaper
    defaults: { _controller: ProjectBCasanetBundle:Admin:addpaper }

答案 1 :(得分:0)

由于您的路由存在于路由器:debug --env = dev中,因此您可能只需要清除缓存。

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

或者如果你使用prod刺激。

答案 2 :(得分:0)

我发现了什么问题。

我运行了一个作曲家no-dev更新并在1天前中断它,它已损坏。今天我更新到Symfony 2.6.5,它解决了我想的问题。谢谢大家!