public function load(ObjectManager $manager) { foreach (range(0, 9) as $i) { $category = new Category(); $category->setName('Category #' . $i); $this->addReference('category-' . $i, $category); $manager->persist($category); } $manager->flush(); foreach (range(0, 99) as $i) { $category = new Category(); $category->setName('Subcategory #' . $i); $category->setParent($this->getReference('category-' . $i % 10)); $this->addReference('subcategory-' . $i, $category); $manager->persist($category); } $manager->flush(); }
public function load(ObjectManager $manager) { $category = new Category(); $category->setTitle('Дома'); $this->setReference("houses", $category); $manager->persist($category); $category = new Category(); $category->setTitle('Квартиры'); $this->setReference("flats", $category); $manager->persist($category); $category = new Category(); $category->setTitle('Участки'); $this->setReference("steads", $category); $manager->persist($category); $category = new Category(); $category->setTitle('Аренда жилья'); $this->setReference("rent", $category); $manager->persist($category); $category = new Category(); $category->setTitle('Коммерция'); $this->setReference("commerce", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Дома в городе"); //$category->setUrl("{{ path('show_category', {'slug': link.title}) }}"); $category->setParent($this->getReference("houses")); $this->setReference("category6", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Дома за городом"); $category->setParent($this->getReference("houses")); $this->setReference("category7", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Комната"); $category->setParent($this->getReference("flats")); $this->setReference("category1", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Однокомнатные квартиры"); $category->setParent($this->getReference("flats")); $this->setReference("category2", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Двокомнатные квартиры"); $category->setParent($this->getReference("flats")); $this->setReference("category3", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Трьохкомнатные квартиры"); $category->setParent($this->getReference("flats")); $this->setReference("category4", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Многокомнатные"); $category->setParent($this->getReference("flats")); $this->setReference("category5", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Дачные участки"); $category->setParent($this->getReference("steads")); $this->setReference("category8", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Участки в городе"); $category->setParent($this->getReference("steads")); $this->setReference("category9", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Участки за городом"); $category->setParent($this->getReference("steads")); $this->setReference("category10", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Аренда коммерции"); $category->setParent($this->getReference("commerce")); $this->setReference("category11", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Продажа коммерции"); $category->setParent($this->getReference("commerce")); $this->setReference("category12", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Дома в аренду"); $category->setParent($this->getReference("rent")); $this->setReference("category13", $category); $manager->persist($category); $category = new Category(); $category->setTitle("Квартиры в аренду"); $category->setParent($this->getReference("rent")); $this->setReference("category14", $category); $manager->persist($category); $manager->flush(); }
/** * {@inheritDoc} */ public function setParent($parent) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setParent', array($parent)); return parent::setParent($parent); }
/** * This method is executed after interact() and initialize(). It usually * contains the logic to execute to complete this command task. */ protected function execute(InputInterface $input, OutputInterface $output) { $startTime = microtime(true); $name = $input->getArgument('name'); $urlName = $input->getArgument('urlName'); $description = $input->getArgument('description'); $parent = $input->getArgument('parent'); $parentObj = null; if (null !== $parent) { $parentObj = $this->em->getRepository('AppBundle:Category')->findOneBy(array('name' => $parent)); } $existingCategory = $this->em->getRepository('AppBundle:Category')->findOneBy(array('name' => $name)); if (null !== $existingCategory) { throw new \RuntimeException(sprintf('There is already a category "%s".', $name)); } // create the user and encode its password $category = new Category(); $category->setName($name); if (empty($urlName)) { $urlName = $name; } $category->setUrlName($urlName); $category->setDescription($description); $category->setParent($parentObj); $this->em->persist($category); $this->em->flush($category); $output->writeln(''); $output->writeln(sprintf('[OK] %s was successfully created', $category->getName())); if ($output->isVerbose()) { $finishTime = microtime(true); $elapsedTime = $finishTime - $startTime; $output->writeln(sprintf('[INFO] New user database id: %d / Elapsed time: %.2f ms', $category->getId(), $elapsedTime * 1000)); } }