Note that there are some explanatory texts on larger screens.

plurals
  1. POFOSRestBundle: The controller must return a response (Array()) given
    primarykey
    data
    text
    <p>I'm starting with FOSRestBundle. I have added this routing configuration:</p> <pre><code>//Sermovi/Bundle/APIBundle/Resources/config/routing.yml sermovi_api_homepage: type: rest resource: Sermovi\Bundle\APIBundle\Controller\DefaultController //app/config/routing.yml sermovi_api: type: rest prefix: /api resource: "@SermoviAPIBundle/Resources/config/routing.yml" </code></pre> <p>And this config.yml</p> <pre><code>fos_rest: routing_loader: default_format: json view: view_response_listener: true sensio_framework_extra: view: annotations: false </code></pre> <p>And this controller:</p> <pre><code>namespace Sermovi\Bundle\APIBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use FOS\RestBundle\Controller\FOSRestController; use Symfony\Component\HttpFoundation\Response; class DefaultController extends FOSRestController { public function getArticlesAction() { $em = $this-&gt;getDoctrine()-&gt;getManager(); $entity = $em-&gt;getRepository('SermoviManagementBundle:Transaction')-&gt;find(776); return array( 'entity' =&gt; $entity ); } } </code></pre> <p>And I'm getting this error:</p> <blockquote> <p>[{"message":"The controller must return a response (Array(entity => Object(Sermovi\Bundle\ManagementBundle\Entity\Transaction)) given).","class":"LogicException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"/home/tirengarfio/workspace/sermovi/app/bootstrap.php.cache","line":2855,"args":[]},{"namespace":"Symfony\Component\HttpKernel","short_class":"HttpKernel","class":"Symfony\Component\HttpKernel\HttpKernel","type":"->","function":"handleRaw","file":"/home/tirengarfio/workspace/sermovi/app/bootstrap.php.cache","line":2817,"args":[["object","Symfony\Component\HttpFoundation\Request"],["string","1"]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"HttpKernel","class":"Symfony\Component\HttpKernel\HttpKernel","type":"->","function":"handle","file":"/home/tirengarfio/workspace/sermovi/app/bootstrap.php.cache","line":2946,"args":[["object","Symfony\Component\HttpFoundation\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\Component\HttpKernel\DependencyInjection","short_class":"ContainerAwareHttpKernel","class":"Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel","type":"->","function":"handle","file":"/home/tirengarfio/workspace/sermovi/app/bootstrap.php.cache","line":2247,"args":[["object","Symfony\Component\HttpFoundation\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"Kernel","class":"Symfony\Component\HttpKernel\Kernel","type":"->","function":"handle","file":"/home/tirengarfio/workspace/sermovi/web/app_dev.php","line":28,"args":[["object","Symfony\Component\HttpFoundation\Request"]]}]}]</p> </blockquote> <p><strong>EDIT:</strong> </p> <p>"Could" I do something like this below? Or since FOSRestBundle is using JMSSerializerBundle I should not do it? </p> <pre><code>$serializedEntity = $this-&gt;container-&gt;get('serializer')-&gt;serialize($entity, 'json'); return new Response($serializedEntity); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload