私はFOSRestBundleとSymfonyフォームを実装しようとしています。 私はこのtutorialを発見したが、私はthis一部FOSRestBundle&無効なフォームCRFトークン
private function processForm(PageInterface $page, array $parameters, $method = "PUT")
{
$form = $this->formFactory->create(new PageType(), $page, array('method' => $method));
$form->submit($parameters, 'PATCH' !== $method);
if ($form->isValid()) { //form is not valid.
$page = $form->getData();
$this->om->persist($page);
$this->om->flush($page);
return $page;
}
throw new InvalidFormException('Invalid submitted data', $form);
}
ERROR: The CSRF token is invalid. Please try to resubmit the form.
Hereに問題があるチュートリアルからコントローラです。そして、ここに私のクラスのコントローラがある:
public function newAction(Request $request)
{
$form = new EntryType();
$newEntry = $this->container->get('entries.entry.handler')->post(
$request->request->get($form->getName())
);
return View::create()
->setStatusCode(200)
->setFormat('json')
->setSerializationContext(SerializationContext::create()->setGroups(array('list')))
->setData($newEntry);
}
私はisValid()
をチェックスキップしたり、何らかの形でこの問題を解決すべきか?どうやって?
[OK] CRFの検証(csrf_protectionは)tutorialの一部3から
CSRF token is invalid when calling rest post api from php Client https://github.com/liuggio/symfony2-rest-api-the-best-2013-way/issues/1#issuecomment-31435232 CSRF validation needed or not when using RESTful API?
どのようにフォームをレンダリングしますか? –
私はしません。私はAPIを介して新しいレコードを追加したい。更新された質問を確認してください – breq
[symfony - CSRFトークンが無効です - FosRestBundle](http://stackoverflow.com/questions/40461760/symfony-csrf-token-is-invalid-fosrestbundle) – Trix