Routes Symfony 4路

Routes Symfony 4路,routes,annotations,symfony4,Routes,Annotations,Symfony4,在Symfony 4上启动项目。但我有问题。当我使用新路线时,我得到“未找到路线”。但类似的路线是正确的。 命令调试:路由器显示旧路线,清除现金对我不起作用,我使用 1)php bin/console cache:clear --env=dev 2)php bin/console cache:clear --env=prod 3)php bin/console cache:clear --env=prod --no-debug 甚至路由名称也不正确 routes.yaml为空(使用注释)。

在Symfony 4上启动项目。但我有问题。当我使用新路线时,我得到“未找到路线”。但类似的路线是正确的。 命令调试:路由器显示旧路线,清除现金对我不起作用,我使用

1)php bin/console cache:clear --env=dev
2)php bin/console cache:clear --env=prod
3)php bin/console cache:clear --env=prod --no-debug
甚至路由名称也不正确

routes.yaml为空(使用注释)。 我的控制器:

namespace App\Controller;
use App\Entity\Category;
use App\Entity\Product;
use App\Entity\Subcategory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Psr\Log\LoggerInterface;

class DefaultController extends AbstractController
{
    /**
     * Matches / exactly
     *
     * @Route("/", name="index")
     */
    public function index()
    {
        $products = $this->getDoctrine()
            ->getRepository(Product::class)
            ->findDiscounts();
        $categories = $this->getDoctrine()
            ->getRepository(Category::class)
            ->findAll();
        return $this->render('default/index.html.twig', compact('products', 'categories'));
    }

    /**
     * Matches /shop/*
     *
     * @Route("/shop/{categoryAlias}", name="shop_show")
     * @param string $categoryAlias
     * @return Response
     */
    public function shop($categoryAlias = 'null')
    {
        if ($categoryAlias != 'null') :
            $response = $this->getDoctrine()
                ->getRepository(Category::class)
                ->findbyAlias($categoryAlias);
            $categories = array(); //Костыль
            $categories[] = $response; //Костыль
            $subcategories = $categories[0]->getSubcategories();
        else :
            $categories = $this->getDoctrine()
                ->getRepository(Category::class)
                ->findAll();
            $subcategories = null;
        endif;
        $allCategories = $this->getDoctrine()
            ->getRepository(Category::class)
            ->findAll();
        return $this->render('default/shop.html.twig', compact('allCategories','subcategories','categories'));
    }

    /**
     * Matches /product/*
     *
     * @Route("/product/{productAlias}", name="product_show")
     * @param string $productAlias
     * @return Response
     */
    public function product($productAlias)
    {
        $product = $this->getDoctrine()
            ->getRepository(Product::class)
            ->findByAlias($productAlias);
        return $this->render('default/product.html.twig', compact('product'));
    }
}
路线/商店正在运行。路线/产品不适用。 我只是从Symfony开始,被困在这里。
谢谢。

手动删除文件夹“缓存”,所有作品

我以前遇到过类似问题,请检查两条不同路径是否有重复/相同的路由名称。