Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make error messages prefix/namespace aware.
  • Loading branch information
markstory committed Jul 4, 2012
1 parent 516b497 commit ceaf2c5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
8 changes: 6 additions & 2 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -495,7 +495,9 @@ public function invokeAction(Request $request) {
if ($this->_isPrivateAction($method, $request)) {
throw new Error\PrivateActionException(array(
'controller' => $this->name . "Controller",
'action' => $request->params['action']
'action' => $request->params['action'],
'prefix' => isset($request->params['prefix']) ? $request->params['prefix'] : '',
'plugin' => $request->params['plugin'],
));
}
return $method->invokeArgs($this, $request->params['pass']);
Expand All @@ -506,7 +508,9 @@ public function invokeAction(Request $request) {
}
throw new Error\MissingActionException(array(
'controller' => $this->name . "Controller",
'action' => $request->params['action']
'action' => $request->params['action'],
'prefix' => isset($request->params['prefix']) ? $request->params['prefix'] : '',
'plugin' => $request->params['plugin'],
));
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Routing/Dispatcher.php
Expand Up @@ -156,7 +156,8 @@ public function dispatch(Request $request, Response $response, $additionalParams
if (!($controller instanceof Controller)) {
throw new Error\MissingControllerException(array(
'class' => Inflector::camelize($request->params['controller']),
'plugin' => empty($request->params['plugin']) ? null : Inflector::camelize($request->params['plugin'])
'plugin' => empty($request->params['plugin']) ? null : Inflector::camelize($request->params['plugin']),
'prefix' => empty($request->params['prefix']) ? null : Inflector::camelize($request->params['prefix']),
));
}

Expand Down
27 changes: 23 additions & 4 deletions lib/Cake/View/Errors/missing_action.ctp
@@ -1,8 +1,5 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -15,17 +12,39 @@
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
use Cake\Core\Configure;
use Cake\Utility\Inflector;
use Cake\Core\Plugin;

$namespace = Configure::read('App.namespace');
if (!empty($plugin)) {
$namespace = $plugin;
}
$prefixNs = '';
if (!empty($prefix)) {
$prefix = Inflector::camelize($prefix);
$prefixNs = '\\' . $prefix;
}
if (empty($plugin)) {
$path = APP_DIR . DS . 'Controller' . DS . $prefix . DS . $controller . '.php' ;
} else {
$path = Plugin::path($plugin) . 'Controller' . DS . $prefix . DS . $class . '.php';
}
?>
<h2><?php echo __d('cake_dev', 'Missing Method in %s', $controller); ?></h2> <p class="error">
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
<?php echo __d('cake_dev', 'The action %1$s is not defined in controller %2$s', '<em>' . $action . '</em>', '<em>' . $controller . '</em>'); ?>
</p>
<p class="error">
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
<?php echo __d('cake_dev', 'Create %1$s%2$s in file: %3$s.', '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>', APP_DIR . DS . 'Controller' . DS . $controller . '.php'); ?>
<?php echo __d('cake_dev', 'Create %1$s%2$s in file: %3$s.', '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>', $path); ?>
</p>
<pre>
&lt;?php
namespace <?= $namespace; ?>\Controller<?= $prefixNs ?>;

use <?= $namespace; ?>\Controller\AppController;

class <?php echo $controller; ?> extends AppController {

<strong>
Expand Down
27 changes: 23 additions & 4 deletions lib/Cake/View/Errors/missing_controller.ctp
@@ -1,8 +1,5 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -16,8 +13,26 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
use Cake\Core\Plugin;
use Cake\Core\Configure;
use Cake\Utility\Inflector;

$pluginDot = empty($plugin) ? null : $plugin . '.';
$namespace = Configure::read('App.namespace');
$prefixNs = '';

if (!empty($prefix)) {
$prefix = Inflector::camelize($prefix);
$prefixNs = '\\' . $prefix;
}
if (!empty($plugin)) {
$namespace = $plugin;
}
if (empty($plugin)) {
$path = APP_DIR . DS . 'Controller' . DS . $prefix . DS . $class . '.php' ;
} else {
$path = Plugin::path($plugin) . 'Controller' . DS . $prefix . DS . $class . '.php';
}

?>
<h2><?php echo __d('cake_dev', 'Missing Controller'); ?></h2>
<p class="error">
Expand All @@ -26,10 +41,14 @@ $pluginDot = empty($plugin) ? null : $plugin . '.';
</p>
<p class="error">
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . $class . '</em>', (empty($plugin) ? APP_DIR . DS : Plugin::path($plugin)) . 'Controller' . DS . $class . '.php'); ?>
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . $class . '</em>', $path); ?>
</p>
<pre>
&lt;?php
namespace <?= $namespace; ?>\Controller<?= $prefixNs; ?>;

use <?= $namespace; ?>\Controller\AppController;

class <?php echo $class . ' extends ' . $plugin; ?>AppController {

}
Expand Down

0 comments on commit ceaf2c5

Please sign in to comment.