Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several ways to setup your Controllers with FOSRestBundle. The way you are doing it, you must return a view. Here is a link to a rest controller on github that may help you out a bit. <a href="https://github.com/liip/LiipHelloBundle/blob/master/Controller/RestController.php" rel="nofollow">LiipHelloBundle</a> has an example. </p> <p>Also, I found it easiest to use the <code>ClassResourceInterface</code> in my controllers. This way, I return an array, and it handles all the serialization itself. It also uses your Controller name to generate the routes that are necessary, so I don't have to manually define any routes. It is my preferred way of setting up the Controller. See the doc entry <a href="https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/5-automatic-route-generation_single-restful-controller.md#implicit-resource-name-definition" rel="nofollow">here</a> for how that works.</p> <p>If you do end up using the <code>ClassResourceInterface</code>, be sure to include the following annotation for each action, it will make it so your returned array is serialized properly:</p> <pre><code>use FOS\RestBundle\Controller\Annotations as Rest; //..... /** * @Rest\View() */ public function cgetAction() {} </code></pre> <p>You might even be able to do that with the way you are setting up the controller, but I haven't tried that before. Let us know if you go that way and it works.</p> <p><strong>UPDATE</strong></p> <p>For those who may be interested in using the FOSRestBundle without using the <code>ClassResourceInterface</code>, the problem with the controller action in the question is that it does not return a view. This should work in the action:</p> <pre><code>class DefaultController extends FOSRestController { public function getArticlesAction() { $em = $this-&gt;getDoctrine()-&gt;getManager(); $entity = $em-&gt;getRepository('SermoviManagementBundle:Transaction')-&gt;find(776); $statusCode = 200; $view = $this-&gt;view($entity, $statusCode); return $this-&gt;handleView($view); } } </code></pre>
    singulars
    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.
    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