/** * Creates and saves a behavior * * @param Request $request * @param $id * @return JsonResponse * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function doCreateBehaviorAction(Request $request, $id) { try { if (!$request->isXmlHttpRequest()) { throw $this->createAccessDeniedException(); } $fc_form = FcFormQuery::create()->findPk($id); if (!$fc_form instanceof FcForm) { throw $this->createNotFoundException(); } $fc_behavior = new FcFormBehavior(); $fc_behavior->setFcForm($fc_form); $fc_behavior->save(); return new JsonResponse(array('success' => true)); } catch (\Exception $e) { return new JsonResponse(array('success' => false, 'view' => 'Error ' . $e->getCode() . ': ' . $e->getMessage())); } }