Symfony 3.4:路线匹配,但在网址中找不到路线

时间:2018-09-18 14:38:38

标签: php symfony routing symfony-3.4

我刚刚像平常一样创建了一个新的控制器,但是这次我遇到了路由问题。

在探查器路线匹配中,但我无法到达并获得No route found for "GET /prezzi/listino"

控制器

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;

class PricesController extends Controller {
    /**
     * @Route("/prezzi/listino", name="prezzi_listino")
     */
    public function pricesListAction()
    {
        $list = $this->getDoctrine()->getRepository('AppBundle:Prices')->findAll();

        return $this->render('prices/list.html.twig', [
            'items' => $list
        ]);
    }
}

调试路由器

$ php bin/console debug:router
 ----------------------------------- ---------- -------- ------ ------------------------------------------------------- 
  Name                                Method     Scheme   Host   Path                                                   
 ----------------------------------- ---------- -------- ------ ------------------------------------------------------- 
[..]
  prezzi_listino                      ANY        ANY      ANY    /prezzi/listino                                        
[..]
 ----------------------------------- ---------- -------- ------ ------------------------------------------------------- 

路由器匹配

$ php bin/console router:match --method GET /prezzi/listino



 [OK] Route "prezzi_listino" matches                                                                                    


+--------------+---------------------------------------------------------+
| Property     | Value                                                   |
+--------------+---------------------------------------------------------+
| Route Name   | prezzi_listino                                          |
| Path         | /prezzi/listino                                         |
| Path Regex   | #^/prezzi/listino$#sD                                   |
| Host         | ANY                                                     |
| Host Regex   |                                                         |
| Scheme       | ANY                                                     |
| Method       | ANY                                                     |
| Requirements | NO CUSTOM                                               |
| Class        | Symfony\Component\Routing\Route                         |
| Defaults     | _controller: AppBundle:Prices:pricesList                |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler |
| Callable     | AppBundle\Controller\PricesController::pricesListAction |
+--------------+---------------------------------------------------------+

关于错误在哪里的任何想法?我认为这是一种分散注意力的原因,我还没有看到这个问题。

1 个答案:

答案 0 :(得分:0)

由于我已尝试将路由添加到实际可用的另一个控制器中,并且似乎不起作用,所以我得出的结论是我无法添加任何新路由,因此这意味着缓存错误。

运行php bin/console cache:clear --env=dev --no-warmup解决了这个问题。