public function saveAction(Request $request, Application $app) { $formCreate = new CreateClientFormProvider($app); $form = $formCreate->create(); $form->handleRequest($request); if ($request->getMethod() === 'POST' && $form->isValid()) { $data = $request->request->get('form'); $clientEntity = new ClientEntity(); $clientEntity->setFirstName($data['first_name']); $clientEntity->setLastName($data['last_name']); $clientEntity->setEmail($data['email']); $clientEntity->setAge($data['age']); $mongoDbService = new MongoDbService(new MongoDbRepository($app['config'])); $result = $mongoDbService->save($clientEntity); if ($result instanceof \MongoDB\InsertOneResult) { return new Response(json_encode(['id' => (string) $result->getInsertedId(), 'result' => true]), 200, ['Content-Type' => 'application/json']); } } return new Response(json_encode(['result' => false]), 503, ['Content-Type' => 'application/json']); }
public function createAction(Application $app) { $formCreate = new CreateClientFormProvider($app); $form = $formCreate->create(); return new Response($app['twig']->render('create.html.twit', ['form' => $form->createView()])); }