missing_controller.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 0.10.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. use Cake\Core\Plugin;
  16. use Cake\Core\Configure;
  17. use Cake\Utility\Inflector;
  18. $pluginDot = empty($plugin) ? null : $plugin . '.';
  19. $namespace = Configure::read('App.namespace');
  20. $prefixNs = $prefixPath = '';
  21. $incompleteInflection = (strpos($class, '_') !== false || strpos($class, '-'));
  22. $originalClass = $class;
  23. $class = Inflector::camelize($class);
  24. if (!empty($prefix)) {
  25. $prefix = array_map('Cake\Utility\Inflector::camelize', explode('/', $prefix));
  26. $prefixNs = '\\' . implode('\\', $prefix);
  27. $prefixPath = implode(DIRECTORY_SEPARATOR, $prefix) . DIRECTORY_SEPARATOR;
  28. }
  29. if (!empty($plugin)) {
  30. $namespace = str_replace('/', '\\', $plugin);
  31. }
  32. if (empty($plugin)) {
  33. $path = APP_DIR . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . $prefixPath . h($class) . 'Controller.php' ;
  34. } else {
  35. $path = Plugin::classPath($plugin) . 'Controller' . DIRECTORY_SEPARATOR . $prefixPath . h($class) . 'Controller.php';
  36. }
  37. $this->layout = 'dev_error';
  38. $this->assign('title', 'Missing Controller');
  39. $this->assign('templateName', 'missing_controller.php');
  40. ?>
  41. <?php $this->start('subheading');?>
  42. <strong>Error</strong>
  43. <?php if ($incompleteInflection): ?>
  44. Your routing resulted in <em><?= h($originalClass) ?></em> as a controller name.
  45. <?php else: ?>
  46. <em><?= h($pluginDot . $class) ?>Controller</em> could not be found.
  47. <?php endif; ?>
  48. <?php $this->end() ?>
  49. <?php $this->start('file'); ?>
  50. <?php if ($incompleteInflection): ?>
  51. <p>The controller name <em><?= h($originalClass) ?></em> has not been properly inflected, and
  52. could not be resolved to a controller that exists in your application.</p>
  53. <p>Ensure that your URL <strong><?= h($this->request->getUri()->getPath()) ?></strong> is
  54. using the same inflection style as your routes do. By default applications use <code>DashedRoute</code>
  55. and URLs should use <strong>-</strong> to separate multi-word controller names.</p>
  56. <?php else: ?>
  57. <p>
  58. In the case you tried to access a plugin controller make sure you added it to your composer file or you use the autoload option for the plugin.
  59. </p>
  60. <p class="error">
  61. <strong>Suggestion</strong>
  62. Create the class <em><?= h($class) ?>Controller</em> below in file: <?= h($path) ?>
  63. </p>
  64. <?php
  65. $code = <<<PHP
  66. <?php
  67. namespace {$namespace}\Controller{$prefixNs};
  68. use {$namespace}\Controller\AppController;
  69. class {$class}Controller extends AppController
  70. {
  71. }
  72. PHP;
  73. ?>
  74. <div class="code-dump"><?php highlight_string($code); ?></div>
  75. <?php endif; ?>
  76. <?php $this->end(); ?>