Answer the question
In order to leave comments, you need to log in
The problem with the route in the controller. Bug?
Hello. I am new to PHP, OOP, frameworks. I can already do something simple, but I continue to study the language itself, patterns and frameworks, respectively. I decided to immerse myself in Symphony, in general I like everything, I can do primitive things. But there was a problem with Routing, I ask for help in solving and, if possible, explaining "what and how":
There is a class:
class ProductController extends AbstractController
{
/**
* @Route("/product/{id}", name="product")
*/
public function show($id,ProductRepository $productRepository)
{
//это я тут уже извращался как мог с условием
if (!$productRepository->findOneBy(['id' => $id]) && !(int)$id ) {
throw new NotFoundHttpException('The product does not exist');
}
return $this->render('product/product/index.html.twig',
['product' => $productRepository->findOneBy(['id' => $id])]
);
}
}
public function show(int $id, ProductRepository $productRepository)
//или
public function show(string $id,ProductRepository $productRepository)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question