承接 mcfedr/json-form 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mcfedr/json-form

最新稳定版本:4.8.0

Composer 安装命令:

composer require mcfedr/json-form

包简介

A couple of helper files for handling json with symfony forms

README 文档

README

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

Latest Stable Version License Build Status

Install

Composer

php composer.phar require mcfedr/json-form

AppKernel

Include the bundle in your AppKernel

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

JSON

The expected JSON will be just like that form values that would be sent.

Suppose you have the following form type

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

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

Then the JSON should be

{
    "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.

Contributing

To run the tests

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

统计信息

  • 总下载量: 87.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-11