Запуск проекта на Symfony 4. Но у меня проблема.Когда я использую новый маршрут, я получаю «Маршрут не найден».Но подобный маршрут верен.Команда debug: маршрутизатор, показывающий старые маршруты, очистка наличных денег у меня не работает, я использовал
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
debug: результат маршрутизатора Даже имена маршрутов неверны.
маршруты. 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 и застрял здесь.Спасибо.