dongzhashou0116 2013-11-05 16:32
浏览 48
已采纳

Symfony找不到路线

I have the weirdest problem. Everything was doing just fine and suddenly symfony shows

"No route found for "GET /"

So i checked router and..none of the routes from my controller were in there.

So i added routing to the routing.yml and right now it throws

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_edit_user" as such route does not exist.") in C:\xampp\htdocs\zadanie\src\Cart\Bundle/Resources/views/User/index.html.twig at line 2

EVEN THOUGH the action which name is "_edit_user" is right under the one that is being called from routing.

What the hell is happening?

EDIT: here is what router:debug says:

_wdt                     ANY    ANY    ANY  /_wdt/{token}
_profiler_home           ANY    ANY    ANY  /_profiler/
_profiler_search         ANY    ANY    ANY  /_profiler/search
_profiler_search_bar     ANY    ANY    ANY  /_profiler/search_bar
_profiler_purge          ANY    ANY    ANY  /_profiler/purge
_profiler_info           ANY    ANY    ANY  /_profiler/info/{about}
_profiler_import         ANY    ANY    ANY  /_profiler/import
_profiler_export         ANY    ANY    ANY  /_profiler/export/{token}.txt
_profiler_phpinfo        ANY    ANY    ANY  /_profiler/phpinfo
_profiler_search_results ANY    ANY    ANY  /_profiler/{token}/search/results
_profiler                ANY    ANY    ANY  /_profiler/{token}
_profiler_router         ANY    ANY    ANY  /_profiler/{token}/router
_profiler_exception      ANY    ANY    ANY  /_profiler/{token}/exception
_profiler_exception_css  ANY    ANY    ANY  /_profiler/{token}/exception.css
_configurator_home       ANY    ANY    ANY  /_configurator/
_configurator_step       ANY    ANY    ANY  /_configurator/step/{index}
_configurator_final      ANY    ANY    ANY  /_configurator/final
blog_show                ANY    ANY    ANY  /

and blog_show is the one I added in the routing.yml..

  • 写回答

1条回答 默认 最新

  • duanjie9630 2013-11-05 18:51
    关注

    Symfony2 doesn't auto-map action methods to route names. If you need an action method to be routable, you have to specify that explicitly.

    I personally like using annotations for routing, so if you want to do the same, then first add this to app/config/routing.yml

    YourBundle:
        resource: "@YourBundle/Controller/"
        type:     annotation
        prefix:   /
    

    Then add your routing information to your controllers. To use the default controller as an example:

    src/Your/Bundle/Controller/DefaultController.php

    <?php
    
    namespace Your\Bundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    
    class DefaultController extends Controller
    {
      /**
       * @Route("desired/edit_user/uri", name="_edit_user")
       */
      public function _edit_userAction()
      {
        /* ... */
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'
  • ¥15 vue+element项目中多tag时,切换Tab时iframe套第三方html页面需要实现不刷新