Я узнаю о контроллерах здесь https://symfony.com/doc/current/controller.html
Контроллер:
Код: Выделить всё
namespace App\Controller;
use App\Model\UserDto;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Attribute\Route;
class QueryController extends AbstractController
{
#[Route('/query', name: 'app_query')]
public function index(
#[MapQueryString] UserDTO $userDto
): JsonResponse {
return $this->json(['dto' => $userDto]);
}
}
Код: Выделить всё
namespace App\Model;
use Symfony\Component\Validator\Constraints as Assert;
class UserDTO
{
public function __construct(
#[Assert\NotBlank]
public string $firstName,
#[Assert\NotBlank]
public string $lastName,
#[Assert\GreaterThan(18)]
public int $age,
) {
}
}
Не удалось денормализовать объект типа «App\Model\UserDto» ,
поддерживающий нормализатор не найден.
Версия Symfony 7
Подробнее здесь: https://stackoverflow.com/questions/783 ... ct-of-type
Мобильная версия