1. Go to this page and download the library: Download mcfedr/json-form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mcfedr / json-form example snippets
public function registerBundles()
{
$bundles = array(
...
new Mcfedr\JsonFormBundle\McfedrJsonFormBundle()
class AccountType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name');
}
public function getBlockPrefix()
{
return 'account';
}
}
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
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.