2017 © Pedro Peláez
 

symfony-bundle json-form

A couple of helper files for handling json with symfony forms

image

mcfedr/json-form

A couple of helper files for handling json with symfony forms

  • Tuesday, July 24, 2018
  • by mcfedr
  • Repository
  • 3 Watchers
  • 11 Stars
  • 57,286 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 19 Versions
  • 5 % Grown

The README.md

Json Form helper

Simply use the JsonControllerTrait and then use forms as you would normally, but they now expect to receive JSON., (*1)

Latest Stable Version License Build Status, (*2)

Install

Composer

php composer.phar require mcfedr/json-form

AppKernel

Include the bundle in your AppKernel, (*3)

public function registerBundles()
{
    $bundles = array(
        ...
        new Mcfedr\JsonFormBundle\McfedrJsonFormBundle()

JSON

The expected JSON will be just like that form values that would be sent., (*4)

Suppose you have the following form type, (*5)

class AccountType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name');
    }

    public function getBlockPrefix()
    {
        return 'account';
    }
}

Then the JSON should be, (*6)

{
    "account": {
        "name": "Fred"
    }
}

Example

class AccountController extends AbstractController
    use JsonControllerTrait;

    /**
     * @Route("/accounts", methods={"POST"})
     */
    public function accountCreateAction(Request $request, $uuid) {
        $account = new Account();
        $form = $this->createJsonForm(AccountType::class, $account);
        $this->handleJsonForm($form, $request);

        $em = $this->getDoctrine()->getManager();
        $em->persist($account);
        $em->flush();

        return $this->json([
            'account' => $account
        ]);
    }
}

For Symfony 3.x you will need to extend Controller because the trait needs access to getParameter method., (*7)

Contributing

To run the tests, (*8)

./vendor/bin/php-cs-fixer fix
./vendor/bin/phpunit
./vendor/bin/phpstan analyse

The Versions

24/07 2018
12/03 2018
14/02 2017

3.2.2

3.2.2.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

json symfony forms

02/02 2016

3.2.1

3.2.1.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

json symfony forms

02/02 2016

3.2.0

3.2.0.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

json symfony forms

01/09 2015

3.1.0

3.1.0.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

json symfony forms

27/01 2015
16/10 2014

2.0.2

2.0.2.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

json symfony forms

15/10 2014

2.0.1

2.0.1.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

json symfony forms

07/10 2014

2.0.0

2.0.0.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

json symfony forms

11/09 2014

1.0.0

1.0.0.0

A couple of helper files for handling json with symfony forms

  Sources   Download

MIT

The Requires