Diferencia entre revisiones de «Subrecursos API Platform»

De Wiki Proyectos Beta
Ir a la navegación Ir a la búsqueda
Línea 7: Línea 7:
= Ejemplo =
= Ejemplo =


== Ejemplo1 ==
== Ejemplo 1 ==


  #[ApiResource(
  #[ApiResource(
Línea 15: Línea 15:
     ],  
     ],  
     operations: [new GetCollection()]
     operations: [new GetCollection()]
)]
== Ejemplo 2 ==
#[ApiResource(
    uriTemplate: '/companies/{companyId}/employees/{id}',
    uriVariables: [
        'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
        'id' => new Link(fromClass: Employee::class),
    ],
    operations: [ new Get() ]
)]
== Ejemplo 3 ==
#[ApiResource(
    uriTemplate: '/companies/{companyId}/employees',
    uriVariables: [
        'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
    ],
    operations: [ new GetCollection() ]
  )]
  )]

Revisión del 12:36 23 dic 2023

Descripción

Recursos =

  • Documentación oficial: EN

Ejemplo

Ejemplo 1

#[ApiResource(
   uriTemplate: '/answers/{id}/related_questions.{_format}',
   uriVariables: [
       'id' => new Link(fromClass: Answer::class, fromProperty: 'relatedQuestions')
   ], 
   operations: [new GetCollection()]
)]

Ejemplo 2

#[ApiResource(
   uriTemplate: '/companies/{companyId}/employees/{id}',
   uriVariables: [
       'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
       'id' => new Link(fromClass: Employee::class),
   ],
   operations: [ new Get() ]
)]

Ejemplo 3

#[ApiResource(
   uriTemplate: '/companies/{companyId}/employees',
   uriVariables: [
       'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
   ],
   operations: [ new GetCollection() ]
)]