1
にはFOSRestBundle、 を使用しています。使用できるフォームのjsonバージョンを生成したいと思います新しいものをPOSTします。fosrestbundle、jsonの小枝ビューを使用する_format結果をhtmlentitiesでエンコードされたレスポンス
この目的のために、私はjson応答を返すいくつかの方法をテストしましたが、いずれの場合も、私のjson文字列の終わりはFOSRestBundleによってjsonencodeされます。次に例を示します。
#in the controller
/**
* @View()
*/
public function newFooAction(Request $request) {
$_format = $request->attributes->get('_format');
$foo = new Foo();
$form = $this->createForm(FooType::class, $foo, ['action' => $this->generateUrl('post_foo', ['_format' => $_format]),'method' => 'POST',]);
return ['form' => $form];
}
#in the foo.json.twig
{{ form | serialize('json') }}
出力は("
に気づく)そのようにする傾向がある:
{"foo":"bar"}
エンティティを適切なjsonにシリアル化するには、[JMSSerialiserBundle](http://jmsyst.com/bundles/JMSSerializerBundle)を使用します。シリアライズ( 'json') '。 '| json_encode()'を使うと、htmlentitiesと同じ問題があります。 – Bruno