I would like to reduce the controller in accordance with the philosophy of "symfony".

namespace AppBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use AppBundle\Entity\Users; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Symfony\Component\HttpFoundation\Request; ... /** * @Route("/save", name="save") * @Method({"GET"}) * @return Response */ public function saveAction() { //возвращает массив пользователей на текущую дату //array( // "Ivan" => 18, // "Ekaterina" => 24, // "Fedor" => 31, //); $users= $this->get("users")->users(); $em = $this->getDoctrine()->getManager(); $checkNow = $this->getDoctrine() ->getRepository('AppBundle:User') ->findOneBy(array("date" => $this->nowDate)); if(null === $checkNow) { foreach($users as $name => $qty) { $userDB = new User(); $userDB->setDate($this->nowDate); $userDB->setQty($qty); $userDB->setName($name); $em->persist($userDB); } $em->flush(); } return new Response("save new users"); } 
  • You can take everything to the service, but I have a question, where did the $this->nowDate - AmsTaFFix property come from in the controller ?
  • AmsTaFFix, thanks already figured out stackoverflow.com/questions/37855568/… , nowDate is DateTime (), is above the code, forgot to specify - user3771955

0