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()
      {
        /* ... */
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!