douyang5943
2015-09-23 10:31
浏览 135
已采纳

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

I have a misterious case of No route found in my application. I use annotations in my controllers. My app/config/routing.yml looks like this:

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

All routes work perfectly fine, but now I created a new controller and it doesn't find its routes.

<?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');
    }
  }
?>

If I visit the url it says No route found for "GET /export". Also if I do router:debug in the console, the route doesn't get listed. I have cleared the cache several times, it doesn't help.

Probably I just forgot a stupid little detail, but I am really stuck right now, so any hints are appreciated.

图片转代码服务由CSDN问答提供 功能建议

我的应用程序中有一个神奇的 No route found 。 我在控制器中使用注释。 我的 app / config / routing.yml 如下所示:

  app:
 resource:“@ AppBundle / Controller /”
 type: 注释
   
 
 

所有路径都可以正常工作,但现在我创建了一个新的控制器并且找不到它的路径。

 &lt;?php 
命名空间AppBundle \ Controller; 
 
使用Symfony \ Component \ HttpFoundation \ Request; 
使用Symfony \ Bundle \ FrameworkBundle \ Controller \ Controller; 
使用Sensio \ Bundle \ FrameworkExtraBundle \  Configuration \ Method; 
使用Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Route; 
使用Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Template; 
使用Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Security; 
使用Sensio \ Bundle \  FrameworkExtraBundle \ Configuration \ ParamConverter; 
 
 / ** 
 *导出控制器。
 * @Route(“/ export”)
 * / 
类ExportController扩展Controller {
 / * 
 * @Route  (“/”)
 * / 
公共函数showExportPage(Request $ request)
 {
 
返回$ this  - &gt;渲染('AppBundle:export.html.twig'); 
} 
} 
?&gt; 
   
 
 

如果我访问网址 说找不到“GET / export”的路由。 此外,如果我在控制台中执行 router:debug ,则不会列出路由。 我已多次清除缓存,但没有帮助。

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpoppu4300 2015-09-23 11:05
    已采纳

    You lack one more asterisk in an annotation block. Like this, it is not parsed by FrameworkExtraBundle

    So you need

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

    instead of

    /*
     * @Route("/")
     */
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题