Starting project on Symfony 4. But i got problem. When i using new route, I get "No route found". But similar route is correct. Command debug:router showing old routes, clearing cash doen't work for me, I used
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:router result Even route names is incorrect.
routes.yaml is empty (using Annotations). My Controller:
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'));
}
}
Route /shop is working. Route /product is not. I'm only starting in Symfony, and stuck here. Thanks.
Manually deleted the folder "cache", all works