public function load(ObjectManager $manager) { // Create needed file if don't exist $types = ['Date', 'Admin', 'Traceback', 'Connections', 'ExpCoffee', 'NormCoffee', 'UpdatedLabel', 'MinMoney', 'QuestionnaireDanke', 'QuestionnaireWelcome', 'Grade', 'Grade2']; $repository = $manager->getRepository('AppBundle:Data'); foreach ($types as $type) { $data = $repository->findOneByFile($type); if ($data == null) { $data = new Data(); $data->SetData(''); $data->SetFile($type); $manager->persist($data); $manager->flush(); } } }
/** * @Route("/", name="index") */ public function indexAction(Request $request) { // Create needed file if don't exist $types = ['Date', 'Admin', 'Traceback', 'Connections']; $em = $this->getDoctrine()->getManager(); $repository = $em->getRepository('AppBundle:Data'); foreach ($types as $type) { $data = $repository->findOneByFile($type); if ($data == null) { $data = new Data(); $data->SetData(''); $data->SetFile($type); $em->persist($data); $em->flush(); } } // Return homepage return $this->render('AppBundle:Index:index.html.twig'); }