예제 #1
0
 public function load(ObjectManager $manager)
 {
     $symbonfy_base_dir = $this->container->getParameter('kernel.root_dir');
     $data_dir = $symbonfy_base_dir . '/Resources/data/';
     $row = 0;
     $fd = fopen($data_dir . 'person.csv', "r");
     if ($fd) {
         while (($data = fgetcsv($fd)) !== false) {
             $row++;
             if ($row == 1) {
                 continue;
             }
             //skip header
             $person = new Person();
             $person->setName($data[0]);
             $person->setAge($data[1]);
             $birthDate = \DateTime::createFromFormat('d/m/Y', $data[2]);
             $person->setBirthDate($birthDate);
             $person->setHeight($data[3]);
             $person->setEmail($data[4]);
             $person->setPhone($data[5]);
             $person->setGender($data[6]);
             $person->setDescends($data[7]);
             $person->setVehicle($data[8]);
             $person->setPreferredLanguage($data[9]);
             $person->setEnglishLevel($data[10]);
             $person->setPersonalWebSite($data[11]);
             $person->setCardNumber($data[12]);
             $person->setIBAN($data[13]);
             $manager->persist($person);
         }
         fclose($fd);
     }
     $manager->flush();
 }
예제 #2
0
 /**
  *@Route("/test")
  **/
 public function createAction()
 {
     $person = new Person();
     $person->setFirstName('User' . rand(10, 10000));
     $person->setLastName('lastname' . rand(10, 10000));
     $person->setAge(rand(18, 99));
     $em = $this->getDoctrine()->getManager();
     $em->persist($person);
     $em->flush();
     return new Response('Added New User: '******'  ' . $person->getLastName() . '  with age:' . $person->getAge());
 }
 /**
  * {@inheritDoc}
  */
 public function setAge($age)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setAge', array($age));
     return parent::setAge($age);
 }