Я не могу понять, если я создам контроллер crud с
bin / console make: crud все маршруты работают с контроллера
нравиться
/**
* @Route("/", name = "product_index", methods = "GET")
*/
public function index(ProductRepository $productRepository): Response
{
return $this->render('product/index.html.twig', ['products' => $productRepository->findAll()]);
}
.
Если я создам контроллер с bin / console make: controller
и сам определяю контроллер с аннотацией, они не работают
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use JMS\Serializer\SerializerBuilder;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\Product;
use App\Repository\ProductRepository;
use JMS\Serializer\SerializationContext;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
class FirstApiController extends AbstractController
{
/**
*
* @Route("/first_api", name = "first_api")
*/
public function index(ProductRepository $productRepository)
{
$data = $productRepository->findAll();
$serializer = SerializerBuilder::create()->build();
# $jsonContent = $serializer->serialize($data, 'json');
$jsonContent = $serializer->serialize($data, 'json', SerializationContext::create()->setGroups(array('details')));
$response = JsonResponse::fromJsonString($jsonContent);
return $response;
}
/*
* @Route("/first_api/send", name = "send")
*
*/
public function send()
{
$a = "text";
return $a;
}
}
Почему этот маршрут не работает
@Route("/first_api/send", name = "send") ?
В routes.yaml я ничего не написал, просто пустой файл.




Я использовал неправильный синтаксис! Я использовал
/* <-- the error is here
* @Route("/first_api/send", name = "send")
*
*/
Мне нужно использовать
/** <-- i nee two "*"
* @Route("/first_api/send", name = "send")
*
*/
public
Думаю, ваша проблема решена!