symfony - Api-platform request issue -




i have 2 entities author , book

book     | manytoone |author id       |           |id idauthor | 

in author controller have action function gets author details , books (using forward function books)

public function authordetailsaction($id){  $author= $this->getdoctrine()->getrepository(author::class)->find($id);  $books= $this->forward('appbundle:book:authorbooks',array('id' => $id));  return array('author' => $author, 'books' => $books);  } 

but shows author informations

or when im rutrning books return $books got error

the controller must return response (array(0 => object(appbundle\entity\book), 1 => object(appbundle\entity\book), 2 => object(appbundle\entity\book)) given). (500 internal server error)

thanks in advance guidance

as looks use api platform, can achieve want without creating custom controller:

  1. add filter author resource able search author name: https://api-platform.com/docs/core/serialization-groups-and-relations#embedding-relations
  2. embed books related author directly in author response: https://api-platform.com/docs/core/filters#search-filter.




wiki

Comments

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

python - Minimize function with Scipy minimize -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -