示例#1
2
 /**
  * @todo перенести в комманды
  * Контроллер для записи Категорий
  * @Secure(roles = "ROLE_ADMIN")
  * @Route("/testxmlcat", name = "testcategories")
  */
 public function reParceCategoriesAction()
 {
     $html = file_get_contents("http://www.medknigaservis.ru/ervr/medknigaservis.xml");
     $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
     $html = iconv("windows-1251", "utf-8", $html);
     $saw = new \nokogiri($html);
     $xml = $saw->get('category')->toArray();
     #echo '<pre>';
     #print_r($xml);
     #echo '</pre>';
     #echo '<hr />';
     for ($i = 0; true; $i++) {
         if (isset($xml[$i]['#text'][0])) {
             echo '<b>' . $xml[$i]['#text'][0] . '</b><br />';
             $cat = new MarketCategory();
             $cat->setName($xml[$i]['#text'][0]);
             $cat->setOfferId($xml[$i]['id']);
             $em = $this->getDoctrine()->getManager();
             $em->persist($cat);
             $em->flush();
         } else {
             break;
         }
     }
     return $this->render('EvrikaMainBundle:Shop:main.html.twig');
 }
示例#2
0
 /**
  * @Route("/market/category/add" , name="market_category_add" )
  */
 public function addCategoryAction()
 {
     $MarketManager = $this->isAuth();
     if (!$this->isAuth()) {
         return $this->redirect($this->generateUrl("market_login"));
     }
     if ($MarketManager) {
         $request = $this->getRequest();
         if ($request->isMethod('POST')) {
             $em = $this->getDoctrine()->getManager();
             $category = new MarketCategory();
             $category->setEnabled($request->get('enabled'));
             $category->setName($request->get('name'));
             $category->setMarketUser($MarketManager);
             $category->setOfferId($request->get('offerId'));
             $em->persist($category);
             $em->flush();
             return $this->redirect($this->generateUrl('market_categor_lists'));
         }
         return $this->render('EvrikaMainBundle:Market:category_.html.twig', array('auth' => $MarketManager));
     }
 }