mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1248 from zoghal/fix-router1
fix currentRoute() when $_currentRoute is empty, return false
This commit is contained in:
commit
cfda4e5c43
2 changed files with 12 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue