Skip to content

Commit

Permalink
Merge pull request #8875 from cakephp/mailer-error
Browse files Browse the repository at this point in the history
Fix errors on missing action/template error page.
  • Loading branch information
markstory committed May 25, 2016
2 parents f2bc2a1 + 6d3f484 commit b0679a2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/Template/Error/missing_action.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,51 @@ if (!empty($prefix)) {
$prefixNs = '\\' . $prefix;
$prefix .= DIRECTORY_SEPARATOR;
}

// Controller MissingAction support
if (isset($controller)) {
$baseClass = $namespace . '\Controller\AppController';
$extends = 'AppController';
$type = 'Controller';
$class = $controller;
}
// Mailer MissingActionException support
if (isset($mailer)) {
$baseClass = 'Cake\Mailer\Mailer';
$type = $extends = 'Mailer';
$class = $mailer;
}

if (empty($plugin)) {
$path = APP_DIR . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . $prefix . h($controller) . '.php' ;
$path = APP_DIR . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $prefix . h($class) . '.php' ;
} else {
$path = Plugin::classPath($plugin) . 'Controller' . DIRECTORY_SEPARATOR . $prefix . h($controller) . '.php';
$path = Plugin::classPath($plugin) . $type . DIRECTORY_SEPARATOR . $prefix . h($class) . '.php';
}

$this->layout = 'dev_error';

$this->assign('title', sprintf('Missing Method in %s', h($controller)));
$this->assign('title', sprintf('Missing Method in %s', h($class)));
$this->assign(
'subheading',
sprintf('The action <em>%s</em> is not defined in <em>%s</em>', h($action), h($controller))
sprintf('The action <em>%s</em> is not defined in <em>%s</em>', h($action), h($class))
);
$this->assign('templateName', 'missing_action.ctp');

$this->start('file');
?>
<p class="error">
<strong>Error: </strong>
<?= sprintf('Create <em>%s::%s()</em> in file: %s.', h($controller), h($action), $path); ?>
<?= sprintf('Create <em>%s::%s()</em> in file: %s.', h($class), h($action), $path); ?>
</p>

<?php
$code = <<<PHP
<?php
namespace {$namespace}\Controller{$prefixNs};
namespace {$namespace}\\{$type}{$prefixNs};
use {$namespace}\Controller\AppController;
use {$baseClass};
class {$controller} extends AppController
class {$class} extends {$extends}
{
public function {$action}()
Expand Down
7 changes: 7 additions & 0 deletions src/Template/Error/missing_template.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ $this->layout = 'dev_error';
$this->assign('title', 'Missing Template');
$this->assign('templateName', 'missing_template.ctp');

$isEmail = strpos($file, 'Email/') === 0;

$this->start('subheading');
?>
<?php if ($isEmail): ?>
<strong>Error: </strong>
<?= sprintf('The template %s</em> was not found.', h($file)); ?>
<?php else: ?>
<strong>Error: </strong>
<?= sprintf('The view for <em>%sController::%s()</em> was not found.', h(Inflector::camelize($this->request->controller)), h($this->request->action)); ?>
<?php endif ?>
<?php $this->end() ?>

<?php $this->start('file') ?>
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Error/ExceptionRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Cake\Error\ExceptionRenderer;
use Cake\Event\Event;
use Cake\Event\EventManager;
use Cake\Mailer\Exception\MissingActionException as MissingMailerActionException;
use Cake\Network\Exception\InternalErrorException;
use Cake\Network\Exception\MethodNotAllowedException;
use Cake\Network\Exception\NotFoundException;
Expand Down Expand Up @@ -583,6 +584,19 @@ public static function exceptionProvider()
],
500
],
[
new MissingMailerActionException([
'mailer' => 'UserMailer',
'action' => 'welcome',
'prefix' => '',
'plugin' => '',
]),
[
'/Missing Method in UserMailer/',
'/<em>UserMailer::welcome\(\)<\/em>/'
],
404
],
[
new Exception('boom'),
[
Expand Down

0 comments on commit b0679a2

Please sign in to comment.