【问题标题】:No route found for "GET /sf/customer-first-progam-level"找不到“GET /sf/customer-first-program-level”的路线
【发布时间】:2017-04-10 20:46:25
【问题描述】:

如标题所示,如果我尝试访问以下 URL,则会遇到该问题:

http://app.local/sf/customer-first-progam-level

这就是我所拥有的:

  • app/routing.yml

    quote:
        resource: "@QuoteBundle/Controller/"
        type:     annotation
        prefix:   /sf
    
  • QuoteBundle/Controller/CustomerFirstProgramLevelController.php

    <?php
    
    namespace QuoteBundle\Controller;
    
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    
    /**
     * @Route("customer-first-program-level")
     */
     class CustomerFirstProgramLevelController extends Controller
     {
        use GridBuilder;
    
        /**
         * @Route("/", name="customer_first_program_level_index")
         * @Method({"GET", "POST"})
         * @param Request $request
         *
         * @return \Symfony\Component\HttpFoundation\Response
         * @throws \LogicException
         */
         public function indexAction(Request $request)
         {
             ...
         }
     }
    

这是我尝试过但没有成功的方法:

  • 清除 prod 和 dev 的缓存
  • 将路线名称更改为其他名称

如果我调试router,我会得到以下结果:

$ symfony_console debug:router
 ------------------------------------ ---------- -------- ------ -------------------------------------------- 
  Name                                 Method     Scheme   Host   Path                                        
 ------------------------------------ ---------- -------- ------ --------------------------------------------                          
  customer_index                       GET|POST   ANY      ANY    /sf/customer/                               
  customer_first_program_level_index   GET|POST   ANY      ANY    /sf/customer-first-program-level/           
  discount_index                       GET|POST   ANY      ANY    /sf/discount/                               
  ....          
 ------------------------------------ ---------- -------- ------ --------------------------------------------

我正在使用 Symfony 3.2.7。有任何想法吗?我没有他们

【问题讨论】:

  • 试试app.local/sf/customer-first-progam-level,最后加上一个斜线。如果您希望网址末尾没有斜杠,请将注释中的“/”更改为“”
  • 我同意@FrankB。您的休息路线不完整
  • @FrankB 这似乎不是问题,我已经尝试添加斜杠并将其从路由中删除,但仍然无法正常工作,这很奇怪,我所有的控制器都具有相同的结构没有一个,但这个失败了
  • 问题在于progam 中缺少r。我投票赞成关闭这个问题,因为它是一个错字。
  • 有时很简单,您看不到问题:-) 感谢您的回复

标签: php symfony symfony-routing symfony-3.2


【解决方案1】:

我会回答自己,并为那些试图回答但问题太虚拟以至于没有人找到它(包括我自己)的人道歉。如果您仔细查看我的测试 URL 和路由定义,您会发现 URL 上有一个拼写错误:

  • 网址:/sf/customer-first-progam-level
  • @路由:customer-first-program-level

问题progam(URL)与program(路由定义)

【讨论】:

    【解决方案2】:

    试试app.local/sf/customer-first-progam-level,最后加一个斜线。如果您希望网址末尾没有斜杠,请将注释中的“/”更改为“”

    【讨论】:

      猜你喜欢
      • 2013-04-29
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多