Pimcore\Model\Staticroute::getByName PHP Method

getByName() public static method

public static getByName ( string $name, $siteId = null ) : Staticroute
$name string
return Staticroute
    public static function getByName($name, $siteId = null)
    {
        $cacheKey = $name . "~~~" . $siteId;
        // check if pimcore already knows the id for this $name, if yes just return it
        if (array_key_exists($cacheKey, self::$nameIdMappingCache)) {
            return self::getById(self::$nameIdMappingCache[$cacheKey]);
        }
        // create a tmp object to obtain the id
        $route = new self();
        try {
            $route->getDao()->getByName($name, $siteId);
        } catch (\Exception $e) {
            Logger::warn($e);
            return null;
        }
        // to have a singleton in a way. like all instances of Element\ElementInterface do also, like Object\AbstractObject
        if ($route->getId() > 0) {
            // add it to the mini-per request cache
            self::$nameIdMappingCache[$cacheKey] = $route->getId();
            return self::getById($route->getId());
        }
    }

Usage Example

 public function removeStaticRoutes()
 {
     $conf = new \Zend_Config_Xml(PIMCORE_PLUGINS_PATH . '/CoreShop/install/staticroutes.xml');
     foreach ($conf->routes->route as $def) {
         $route = Staticroute::getByName($def->name);
         if ($route) {
             $route->delete();
         }
     }
 }
All Usage Examples Of Pimcore\Model\Staticroute::getByName