Exemplo n.º 1
0
 /**
  * Find model from URL.
  *
  * @param string $url
  * @return string|null
  */
 protected static function findPageModel($url)
 {
     if (self::$urlToModel === null) {
         $cacheName = __CLASS__ . '_' . 'UrlToModel';
         if ((self::$urlToModel = Curry_Core::$cache->load($cacheName)) === false) {
             self::$urlToModel = PageQuery::create()->filterByModelRoute(null, Criteria::ISNOTNULL)->find()->toKeyValue('Url', 'ModelRoute');
             Curry_Core::$cache->save(self::$urlToModel, $cacheName);
         }
     }
     return isset(self::$urlToModel[$url]) ? self::$urlToModel[$url] : null;
 }
Exemplo n.º 2
0
 /**
  * Handler for reverse-routing.
  *
  * @param string $path
  * @param string|array $query
  */
 public function reverseRoute(&$path, &$query)
 {
     // remove matching base path
     $baseUrl = Curry_URL::getDefaultBaseUrl();
     $basePath = $baseUrl['path'];
     $basePathRemoved = false;
     if (Curry_String::startsWith($path, $basePath) && $path !== '/') {
         $path = substr($path, strlen($basePath));
         $basePathRemoved = true;
     }
     Curry_Route_ModelRoute::reverse($path, $query);
     // re-add base path if it was removed
     if ($basePathRemoved) {
         $path = $basePath . $path;
     }
 }