Using FOSRestBundle with forms

Noob, a question related to FOSRestBundle, JMSSerializerBundle and templates.

I am trying to replace some existing code that is currently outputting json via twig to use FOSRestBundle. This was successful when the content passed from the controller was initially in arrays, but now I'm trying to pass the form to a FOSRestBundle, as a result, my values ​​are never returned.

The code below replicates the script

/** * my sample get action * @View(templateVar="form") */ public function getAction($id) { ... $form = $this->createFormBuilder(array('myValue' => 'SOMEVALUE')) ->add('myValue', 'hidden') ->getForm(); $view = FOSView::create($form); $view->setFormat('json'); return $this->get('fos_rest.view_handler')->handle($view); } 

returns

 {"children":{"_token":[],"myValue":[]}} 

what I expected to see here was something like:

 {"children":{"_token": "mylongtoken","myValue": "SOMEVALUE"}} 

I based my code on examples in LiipHelloBundle, if I am not mistaken, does this correspond to the examples they provide? Any ideas I'm wrong about?

+8
php symfony fosuserbundle
source share
1 answer

OK, the not-so-clean solution I would expect in Symfony, but it works like this:

 $form->createView()->get('form')->get('form')->getChild('myValue')->get('choices') 

It returns me myValue objects:

{"28": "Default1", "103": "test"}

+2
source share

All Articles