Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Client Entity
- */
- class Client
- {
- /**
- * @Groups({"client"})
- *
- * @var integer
- */
- private $id;
- /**
- * @Groups({"client"})
- *
- * @var string
- */
- private $name;
- /**
- * @Groups({"client"})
- *
- * @var \DateTime
- */
- private $created;
- /**
- * @Groups({"project"})
- *
- * @var \Doctrine\Common\Collections\Collection
- */
- private $projects;
- // Getters/setters...
- }
- // ------------------------------------------------------------------------------------------------------------
- /*
- * Base Controller
- */
- protected function buildResponse($data, $code = Codes::HTTP_OK)
- {
- // ...
- $parameters = $this->request->query->all();
- $view = View::create($responseData, $code);
- if (array_key_exists('include', $parameters)) {
- $context = SerializationContext::create()->setGroups($parameters['include']);
- $view->setSerializationContext($context);
- }
- return $this->viewHandler->handle($view);
- }
- // ------------------------------------------------------------------------------------------------------------
- /*
- * Query (including a relationship)
- */
- /posts?include[]=comment
- {
- id: 3,
- name: "Post 1 title",
- created: "2016-03-22T17:58:16+0000",
- comments: [
- {
- id: 4,
- body: "Comment body..."
- },
- {
- id: 5,
- body: "Comment body..."
- }
- ]
- }
- // ------------------------------------------------------------------------------------------------------------
- /*
- * Query (no relationships)
- */
- /clients?include[]=client
- {
- id: 3,
- name: "Post 1 title",
- created: "2016-03-22T17:58:16+0000"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement