Skip to content
Permalink
Browse files

Add an error template for missing routes.

Having an error page that shows all the connected routes will help
developers figure out routing errors better.
  • Loading branch information...
markstory committed Jul 1, 2014
1 parent a9ba33d commit e26daf510902869e992f9abfea149825788397c0
Showing with 53 additions and 0 deletions.
  1. +9 −0 src/Routing/Router.php
  2. +44 −0 src/Template/Error/missing_route.ctp
@@ -1178,6 +1178,15 @@ public static function plugin($name, $options = [], $callback = null) {
static::scope($options['path'], $params, $callback);
}
/**
* Get the route scopes and their connected routes.
*
* @return array
*/
public static function routes() {
return array_values(static::$_pathScopes);
}
/**
* Loads route configuration
*
@@ -0,0 +1,44 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 0.10.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Routing\Router;
use Cake\Utility\Debugger;
?>
<h2>Missing Route</h2>
<p class="error">
<strong>Error: </strong>
<?= $error->getMessage(); ?>
</p>

<h3>Connected Routes</h3>
<?php
foreach (Router::routes() as $scope):
printf('<h4>Scope: %s</h4>', $scope->path());
echo '<table cellspacing="0" cellpadding="0">';
echo '<tr><th>Template</th><th>Defaults</th><th>Options</th></tr>';
foreach ($scope->routes() as $route):
echo '<tr>';
printf(
'<th width="25%%">%s</th><th>%s</th><th width="20%%">%s</th>',
$route->template,
Debugger::exportVar($route->defaults),
Debugger::exportVar($route->options)
);
echo '</tr>';
endforeach;
echo '</table>';
endforeach;

0 comments on commit e26daf5

Please sign in to comment.
You can’t perform that action at this time.