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 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用