Exemple #1
0
 public function load(ObjectManager $manager)
 {
     $alias1 = new Alias();
     $alias1->setAlias('/test1');
     $alias1->setTruepath('/testredirect/test1');
     $manager->persist($alias1);
     $alias2 = new Alias();
     $alias2->setAlias('/test2');
     $alias2->setTruepath('/testredirect/johndoe');
     $manager->persist($alias2);
     $alias3 = new Alias();
     $alias3->setAlias('/test3');
     $alias3->setTruepath('/nopath/johndoe');
     $manager->persist($alias3);
     $manager->flush();
 }
Exemple #2
0
 /**
  * 
  * @param type $alias
  * @param type $truepath
  * @return boolean
  * @throws \InvalidArgumentException
  * @throws DuplicateAliasException
  */
 public function createAlias($alias, $truepath)
 {
     if ($alias == '' || $alias == NULL) {
         throw new \InvalidArgumentException('Alias cannot be null or empty');
     }
     if ($truepath == '' || $truepath == NULL) {
         throw new \InvalidArgumentException('Truepath cannot be null or empty');
     }
     $em = $this->container->get('Doctrine')->getManager();
     /* @var $em \Doctrine\ORM\EntityManager */
     if ($oldalias = $em->getRepository('matuckAliasBundle:Alias')->findOneBy(array('alias' => $alias))) {
         throw new DuplicateAliasException(sprintf('The alias %s already exists and points to %s', $alias, $oldalias->getTruepath()));
     }
     $newalias = new Alias();
     $newalias->setAlias($alias);
     $newalias->setTruepath($truepath);
     $em->persist($newalias);
     $em->flush();
     return true;
 }