1

Imagine the following simple form type in a restul symfony2 application:

<?php
namespace Acme\DemoBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class DemoChoiceFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add("description", "choice", array(
                "choices" => array(
                    "foo" => "Foo",
                    "bar" => "Bar",
                    "baz" => "Baz",
                    ),
                "empty_value" => "Choose!",
                "required" => true
            ));
    }
}

Using FOSRestBundle to create a RESTful controller the implementation for fetching this form type would return something like {"children":{"description":[]}} (assuming JSON as default).

Would it be possible - and how - to have the choices serialized as well? Or am I misunderstanding something here? This example only has 3 hard-coded choices, but what about e.g. an entity with 20/30/40/… ? There must be a way to provide that information to the requesting client.

nietonfir
  • 4,797
  • 6
  • 31
  • 43

0 Answers0