/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $userAdmin = new Author('Angel', 'Barcia'); $userAdmin->setName('Angel'); $userAdmin->setSurname('Barcia'); $manager->persist($userAdmin); $manager->flush(); }
/** * @Route("/article/lmh", name="article_show") */ public function showActionLastModifiedHeader(Author $article, Request $request) { $author = $article->getAuthor(); $articleDate = new \DateTime($article->getUpdatedAt()); $authorDate = new \DateTime($author->getUpdatedAt()); $date = $authorDate > $articleDate ? $authorDate : $articleDate; $response = new Response(); $response->setLastModified($date); // Set response as public. Otherwise it will be private by default. $response->setPublic(); if ($response->isNotModified($request)) { return $response; } // ... do more work to populate the response with the full content return $response; }
protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); $em = $this->getContainer()->get('doctrine')->getManager(); $username = $dialog->ask($output, 'Enter admin username: '******''); $firstname = $dialog->ask($output, 'Firstname: ', ''); $lastname = $dialog->ask($output, 'Lastname: ', ''); $email = $dialog->ask($output, 'Email: ', ''); $password = $dialog->ask($output, 'Password: '******''); $repeatPassword = $dialog->ask($output, 'Repeat password: '******''); if ($password != $repeatPassword) { die('Different passwords!' . "\n"); } if ($em->getRepository("AppBundle:Author")->findOneBy(["username" => $username]) || $em->getRepository("AppBundle:Author")->findOneBy(["email" => $email])) { die('User with those login or password already exist!' . "\n"); } else { $encoder = $this->getContainer()->get('security.password_encoder'); $admin = new Author(); $admin->setUsername($username); $admin->setFirstname($firstname); $admin->setLastname($lastname); $admin->setEmail($email); $admin->setIsAdmin(true); $encoded = $encoder->encodePassword($admin, $password); $admin->setPassword($encoded); $em->persist($admin); $em->flush(); } }
/** * @Route("/author", name="Author pflegen") */ public function authorAction() { $author = new Author(); $author->setName("Ali"); $author->setGender("Mann"); // ... do something to the $author object $validator = $this->get('validator'); $errors = $validator->validate($author); if (count($errors) > 0) { /* * Uses a __toString method on the $errors variable which is a * ConstraintViolationList object. This gives us a nice string * for debugging. */ $errorsString = (string) $errors; return new Response($errorsString); } else { $em = $this->getDoctrine()->getManager(); $em->persist($author); $em->flush(); } return new Response('The author is valid! Yes!'); }
/** * @param Author $author * @return \Symfony\Component\Form\Form */ private function createDeleteAuthorForm(Author $author) { return $this->createFormBuilder()->setAction($this->generateUrl('delete-author', array('id' => $author->getId())))->setMethod('DELETE')->getForm(); }
/** * Ajax action to create a new Author entity. * * @Route("/post", name="app_author_post") * @Method("POST") */ public function postAction(Request $request) { $requestContent = $request->getContent(); $pushedData = json_decode($requestContent); $refData = []; $returnData = []; foreach ($pushedData as $entityData) { $refId = $entityData->tempId; $shortName = $entityData->shortName; $lastName = $entityData->last; $fullName = $entityData->first . $entityData->middle . $entityData->last . $entityData->suffix; $entity = new Author(); $entity->setShortName($shortName); $entity->setLastName($lastName); $entity->setFullName($fullName); $refData[$refId] = $entity; $em = $this->getDoctrine()->getManager(); $em->persist($entity); } $em->flush(); foreach ($refData as $refId => $entity) { $returnData[$refId] = $entity->getId(); } // $returnData[$name] = [ "id" => $entity->getId() ]; // $entityData->id = $entity->getId(); $response = new JsonResponse(); $response->setData(array('author' => $returnData)); return $response; }
/** * Add author * * @param \AppBundle\Entity\Author $author * * @return Article */ public function addAuthor(\AppBundle\Entity\Author $author) { $author->setArticle($this); $this->authors[] = $author; return $this; }
/** * @param Author $author * * @return Form */ private function createDeleteForm(Author $author) { $options = ['action' => $this->generateUrl('author_remove', ['id' => $author->getId()]), 'method' => 'DELETE']; return $this->createFormBuilder(null, $options)->add('Delete', 'submit')->getForm(); }
/** * @param ArrayCollection $authors */ public function setAuthors($authors) { if (is_null($authors)) { $author = new Author(); $author->setName('N/A'); $this->authors = $author; } else { $this->authors = $authors; } }