Symfony:在新控制器中找不到路由

时间:2015-09-23 10:31:10

标签: php symfony routing

我的应用程序中有一个No route found的神秘案例。我在控制器中使用注释。我的app/config/routing.yml看起来像这样:

app:
    resource: "@AppBundle/Controller/"
    type:     annotation

所有路线都运行得很好,但现在我创建了一个新的控制器并且找不到它的路线。

<?php
  namespace AppBundle\Controller;

  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

  /**
   * Export controller.
   * @Route("/export")
   */
  class ExportController extends Controller{
    /*
     * @Route("/")
     */
    public function showExportPage(Request $request)
    {
        return $this->render('AppBundle:export.html.twig');
    }
  }
?>

如果我访问网址,则会显示No route found for "GET /export"。此外,如果我在控制台中执行router:debug,则不会列出路由。我已多次清除缓存,但没有帮助。

可能我只是忘记了一个愚蠢的小细节,但我现在真的被困住了,所以任何提示都会受到赞赏。

1 个答案:

答案 0 :(得分:3)

注释块中缺少一个星号。 像这样,它不会被FrameworkExtraBundle

解析

所以你需要

/**
 * @Route("/")
 */

而不是

/*
 * @Route("/")
 */