Пользовательские ссылки на несколько полей

Я смотрю на перемещение исторического приложения через api-platform.com на Symfony, и по разным причинам URL не должны меняться.

В настоящее время у меня есть URL в формате people/{name}/{date}/{number} / например: example.com/people/geoff/2018-01-02/23/ а также example.com/people/bloggs/2018-05-23/1/ ,

Моя сущность «люди» имеет следующий формат:

class People {

/**
* @var int The unique id
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @var string Name of the person.
*
* @ORM\Column(type="string")
*/
private $person;

/**
* @var \DateTimeInterface Date of the entry.
*
* @ORM\Column(type="date_immutable")
*/
private $date;

/**
* @var int Number of entry that person made that day.
*
* @ORM\Column(type="integer")
*/
private $number;
}

Как мне настроить это (Symfony 4.1.3 / Api-Platform / api-pack 1.1), чтобы сохранить синтаксис URL?

Я попытался настроить:

конфигурации / маршруты / api_platform.yaml

api_people_by_date:
path: '/api/people/{name}/{date}/{number}'
methods: ['GET']
defaults:
_controller: App\Controller\PeopleController:peopleGetByDate
_api_resource_class: 'App\Entity\People'
_api_collection_operation_name: 'people_date'

App \ Контроллеры \ PeopleController:

class PeopleController extends Controller {

public function peopleGetByDate(string $name,string $date,string $number) {
return $this->getDoctrine()->getRepository(People::class)->findBy(
[
'name'=>$name,
'date'=>$date,
'number'=>$number
]
);
}
}

Entity / People.php:

...
* @ApiResource(
*     attributes={"order"={"id":"DESC"}},
*     collectionOperations={"get"},
*     itemOperations={"get"={"method"="GET","route_name"="api_people_by_date"}}
*   )
...

но это дает ошибку "hydra:description": "No item route associated with the type \"App\\Entity\\People\".",

Куда я иду не так?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector