在多个字段上的自定义网址

时间:2018-08-12 18:50:59

标签: php symfony api-platform.com

我正在考虑在Symfony上的api-platform.com上移动历史应用程序,并且由于各种原因,URL不应更改。

我目前有people/{name}/{date}/{number}格式的URL /例如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语法?

我尝试设置:

config / routes / 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 \ Controllers \ 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 个答案:

没有答案