示例#1
0
 /**
  * should be called in beforeRender()
  * 
  */
 public static function init(View $View)
 {
     $params = $View->request->params;
     if (Configure::read('UrlCache.pageFiles')) {
         $cachePageKey = '_misc';
         if (is_object($View)) {
             $path = $View->request->here;
             if ($path == '/') {
                 $path = 'uc_homepage';
             } else {
                 $path = strtolower(Inflector::slug($path));
             }
             if (empty($path)) {
                 $path = 'uc_error';
             }
             $cachePageKey = '_' . $path;
         }
         self::$cachePageKey = self::$cacheKey . $cachePageKey;
         self::$cachePage = Cache::read(self::$cachePageKey, '_cake_core_');
     }
     self::$cache = Cache::read(self::$cacheKey, '_cake_core_');
     # still old "prefix true/false" syntax?
     if (Configure::read('UrlCache.verbosePrefixes')) {
         unset(self::$paramFields[3]);
         self::$paramFields = array_merge(self::$paramFields, (array) Configure::read('Routing.prefixes'));
     }
     self::$extras = array_intersect_key($params, array_combine(self::$paramFields, self::$paramFields));
     $defaults = array();
     foreach (self::$paramFields as $field) {
         $defaults[$field] = '';
     }
     self::$extras = array_merge($defaults, self::$extras);
 }
示例#2
0
 public function testUrlWithoutVerbosePrefixes()
 {
     $this->skipIf(true, 'doesnt work yet');
     Configure::delete('UrlCache');
     Configure::write('UrlCache.active', true);
     Configure::write('UrlCache.pageFiles', true);
     Configure::write('UrlCache.verbosePrefixes', false);
     UrlCacheManager::$paramFields = array('controller', 'plugin', 'action', 'prefix');
     $this->HtmlHelper->beforeRender('foo');
     $url = $this->HtmlHelper->url(array('plugin' => 'tools', 'controller' => 'posts', 'action' => 'view', 'prefix' => 'admin'));
     $this->assertEquals(array('41d5d7eb9442adbe76e6c7ebbb02ecc7'), array_keys(UrlCacheManager::$cache));
     $this->assertEquals('/admin/tools/posts/view', $url);
     $url = $this->HtmlHelper->url(array('plugin' => 'tools', 'controller' => 'posts', 'action' => 'view', 'prefix' => 'admin', 'some' => 'param'));
     $this->HtmlHelper->url(array('action' => 'view', 'controller' => 'posts', 'plugin' => 'tools', 'some' => 'param', 'prefix' => 'admin'));
     $this->assertEquals('/admin/tools/posts/view/some:param', $url);
     $this->assertEquals(array('6a7091b88c8132ebb5461851808d318a'), array_keys(UrlCacheManager::$cachePage));
     $this->HtmlHelper->afterLayout('foo');
 }