diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 201a38b99..0733a4940 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -223,6 +223,10 @@ class Dispatcher extends Object { 'url' => $url, 'base' => $this->base))); } + + $controller->Component->initialize($controller); + $controller->beforeFilter(); + $controller->Component->startup($controller); return $this->_invoke($controller, $this->params, $missingAction); } /** @@ -675,10 +679,16 @@ class Dispatcher extends Object { } if (Configure::read('Cache.check') === true) { - $filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '.php'; + $path = $this->here; + if ($this->here == '/') { + $path = 'home'; + } + $path = Inflector::slug($path); + + $filename = CACHE . 'views' . DS . $path . '.php'; if (!file_exists($filename)) { - $filename = CACHE . 'views' . DS . Inflector::slug($this->here) . '_index.php'; + $filename = CACHE . 'views' . DS . $path . '_index.php'; } if (file_exists($filename)) { diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 14da811ea..2098f19f8 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -375,6 +375,7 @@ class Controller extends Object { /** * Loads Model classes based on the the uses property * see Controller::loadModel(); for more info + * Loads Components and prepares them for initailization * * @return mixed true if models found and instance created, or cakeError if models not found. * @access public @@ -401,9 +402,6 @@ class Controller extends Object { } } } - $this->Component->initialize($this); - $this->beforeFilter(); - $this->Component->startup($this); return true; } /** diff --git a/cake/libs/error.php b/cake/libs/error.php index d1193a588..5fb23c2c8 100644 --- a/cake/libs/error.php +++ b/cake/libs/error.php @@ -46,6 +46,7 @@ class CakeErrorController extends AppController { $this->_set(Router::getPaths()); $this->params = Router::getParams(); $this->constructClasses(); + $this->Component->initialize($this); $this->_set(array('cacheAction' => false, 'viewPath' => 'errors')); } diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index 50b949089..694d2bf43 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -222,7 +222,11 @@ class CacheHelper extends AppHelper { } else { $cacheTime = strtotime($timestamp, $now); } - $cache = Inflector::slug($this->here); + $path = $this->here; + if ($this->here == '/') { + $path = 'home'; + } + $cache = Inflector::slug($path); if (empty($cache)) { return; diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index b6a6741f3..3e0ba9af5 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -1316,8 +1316,8 @@ class DispatcherTest extends UnitTestCase { $url = '/'; ob_start(); - $out = $dispatcher->dispatch($url); - ob_get_clean(); + $dispatcher->dispatch($url); + $out = ob_get_clean(); ob_start(); $dispatcher->cached($url); @@ -1328,7 +1328,8 @@ class DispatcherTest extends UnitTestCase { $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $this->assertEqual($result, $expected); - $filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; + + $filename = $this->__cachePath($dispatcher->here); unlink($filename); $dispatcher->base = false; @@ -1347,7 +1348,7 @@ class DispatcherTest extends UnitTestCase { $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $this->assertEqual($result, $expected); - $filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; + $filename = $this->__cachePath($dispatcher->here); unlink($filename); $url = 'TestCachedPages/index'; @@ -1365,7 +1366,7 @@ class DispatcherTest extends UnitTestCase { $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $this->assertEqual($result, $expected); - $filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; + $filename = $this->__cachePath($dispatcher->here); unlink($filename); $url = 'TestCachedPages/test_nocache_tags'; @@ -1383,7 +1384,7 @@ class DispatcherTest extends UnitTestCase { $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached); $this->assertEqual($result, $expected); - $filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php'; + $filename = $this->__cachePath($dispatcher->here); unlink($filename); } /** @@ -1610,6 +1611,27 @@ class DispatcherTest extends UnitTestCase { } } } +/** + * cachePath method + * + * @param mixed $her + * @access private + * @return string + */ + function __cachePath($here) { + $path = $here; + if ($here == '/') { + $path = 'home'; + } + $path = Inflector::slug($path); + + $filename = CACHE . 'views' . DS . $path . '.php'; + + if (!file_exists($filename)) { + $filename = CACHE . 'views' . DS . $path . '_index.php'; + } + return $filename; + } /** * tearDown method * diff --git a/cake/tests/cases/libs/controller/component.test.php b/cake/tests/cases/libs/controller/component.test.php index b075ac39a..daf5363a1 100644 --- a/cake/tests/cases/libs/controller/component.test.php +++ b/cake/tests/cases/libs/controller/component.test.php @@ -292,6 +292,7 @@ class ComponentTest extends CakeTestCase { $Controller =& new ComponentTestController(); $Controller->components = array('Apple'); $Controller->constructClasses(); + $Controller->Component->initialize($Controller); $this->assertTrue(is_a($Controller->Apple, 'AppleComponent')); $this->assertTrue(is_a($Controller->Apple->Orange, 'OrangeComponent')); @@ -306,6 +307,9 @@ class ComponentTest extends CakeTestCase { $Controller =& new ComponentTestController(); $Controller->components = array('Apple'); $Controller->constructClasses(); + $Controller->Component->initialize($Controller); + $Controller->beforeFilter(); + $Controller->Component->startup($Controller); $this->assertTrue(is_a($Controller->Apple, 'AppleComponent')); $this->assertEqual($Controller->Apple->testName, 'ComponentTest'); @@ -319,6 +323,7 @@ class ComponentTest extends CakeTestCase { $Controller =& new ComponentTestController(); $Controller->components = array('Orange', 'Banana'); $Controller->constructClasses(); + $Controller->Component->initialize($Controller); $this->assertEqual($Controller->Banana->testField, 'OrangeField'); $this->assertEqual($Controller->Orange->Banana->testField, 'OrangeField'); @@ -336,6 +341,7 @@ class ComponentTest extends CakeTestCase { $Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple'); $Controller->constructClasses(); + $Controller->Component->initialize($Controller); $this->assertTrue(is_a($Controller->ParamTest, 'ParamTestComponent')); $this->assertTrue(is_a($Controller->ParamTest->Banana, 'BananaComponent')); @@ -349,6 +355,7 @@ class ComponentTest extends CakeTestCase { $Controller =& new ComponentTestController(); $Controller->components = array('ParamTest' => array('test' => 'value'), 'Orange' => array('ripeness' => 'perfect')); $Controller->constructClasses(); + $Controller->Component->initialize($Controller); $this->assertEqual($Controller->Orange->settings, array('colour' => 'blood orange', 'ripeness' => 'perfect')); $this->assertEqual($Controller->ParamTest->test, 'value'); diff --git a/cake/tests/cases/libs/controller/components/cookie.test.php b/cake/tests/cases/libs/controller/components/cookie.test.php index 703c7e76d..e0887c377 100644 --- a/cake/tests/cases/libs/controller/components/cookie.test.php +++ b/cake/tests/cases/libs/controller/components/cookie.test.php @@ -51,6 +51,9 @@ class CookieComponentTest extends CakeTestCase { function start() { $this->Controller = new CookieComponentTestController(); $this->Controller->constructClasses(); + $this->Controller->Component->initialize($this->Controller); + $this->Controller->beforeFilter(); + $this->Controller->Component->startup($this->Controller); $this->Controller->Cookie->destroy(); } diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index eb34cfe38..12c14a7fa 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -138,9 +138,16 @@ class RequestHandlerComponentTest extends CakeTestCase { function testDisabling() { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->_init(); + $this->Controller->Component->initialize($this->Controller); + $this->Controller->beforeFilter(); + $this->Controller->Component->startup($this->Controller); $this->assertEqual($this->Controller->params, array('isAjax' => true)); $this->Controller = new RequestHandlerTestDisabledController(array('components' => array('RequestHandler'))); + $this->Controller->constructClasses(); + $this->Controller->Component->initialize($this->Controller); + $this->Controller->beforeFilter(); + $this->Controller->Component->startup($this->Controller); $this->assertEqual($this->Controller->params, array()); unset($_SERVER['HTTP_X_REQUESTED_WITH']); }