Merge pull request #1248 from zoghal/fix-router1

fix currentRoute() when $_currentRoute is empty, return false
This commit is contained in:
Mark Story 2013-04-26 07:00:33 -07:00
commit cfda4e5c43
2 changed files with 12 additions and 1 deletions

View file

@ -1093,7 +1093,8 @@ class Router {
* @return CakeRoute Matching route object.
*/
public static function currentRoute() {
return self::$_currentRoute[count(self::$_currentRoute) - 1];
$count = count(self::$_currentRoute) - 1;
return ($count >= 0) ? self::$_currentRoute[$count] : false;
}
/**

View file

@ -2161,6 +2161,16 @@ class RouterTest extends CakeTestCase {
$this->assertEquals(Router::stripPlugin($url, null), $url);
}
/**
* testCurrentRouteWhenNonExistentRoute
*
* @return void
*/
public function testCurrentRouteWhenNonExistentRoute() {
$route = Router::currentRoute();
$this->assertFalse($route);
}
/**
* testCurrentRoute
*