/**
  * Обрабатывает форму создания/изменения карточки клиента.
  * 
  * @param Client $client Экземпляр клиента.
  * @return Response|FormInterface
  */
 private function processForm(Client $client)
 {
     // Определяем статус-код успешного завершения в зависимости от того
     // создается ли новый клиент или изменяется существующий.
     $statusCode = is_null($client->getId()) ? Codes::HTTP_CREATED : Codes::HTTP_NO_CONTENT;
     $form = $this->createForm(new ClientType(), $client);
     $form->submit($this->getRequest(), is_null($client->getId()));
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($client);
         $em->flush($client);
         // В соответствии со спецификацией HTTP возвращаем URI
         // созданного/измененного ресурса используя заголовок Location.
         $response = new Response();
         $response->setStatusCode($statusCode);
         $response->headers->set('Location', $this->generateUrl('app_client_get', array('id' => $client->getId()), true));
         return $response;
     }
     return $form;
 }
Example #2
0
 /**
  * Creates a form to delete a Client entity.
  *
  * @param Client $client The Client entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Client $client)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('admin_client_delete', array('id' => $client->getId())))->setMethod('DELETE')->getForm();
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }