missing_controller.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\Configure;
  16. use Cake\Core\Plugin;
  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. $filePath = 'Controller' . DIRECTORY_SEPARATOR . $prefixPath . h($class) . 'Controller.php';
  33. if (empty($plugin)) {
  34. $path = APP_DIR . DIRECTORY_SEPARATOR . $filePath;
  35. } else {
  36. $path = Plugin::classPath($plugin) . $filePath;
  37. }
  38. $this->layout = 'dev_error';
  39. $this->assign('title', 'Missing Controller');
  40. $this->assign('templateName', 'missing_controller.php');
  41. ?>
  42. <?php $this->start('subheading');?>
  43. <strong>Error</strong>
  44. <?php if ($incompleteInflection): ?>
  45. Your routing resulted in <em><?= h($originalClass) ?></em> as a controller name.
  46. <?php else: ?>
  47. <em><?= h($pluginDot . $class) ?>Controller</em> could not be found.
  48. <?php endif; ?>
  49. <?php $this->end() ?>
  50. <?php $this->start('file'); ?>
  51. <?php if ($incompleteInflection): ?>
  52. <p>The controller name <em><?= h($originalClass) ?></em> has not been properly inflected, and
  53. could not be resolved to a controller that exists in your application.</p>
  54. <p>Ensure that your URL <strong><?= h($this->request->getUri()->getPath()) ?></strong> is
  55. using the same inflection style as your routes do. By default applications use <code>DashedRoute</code>
  56. and URLs should use <strong>-</strong> to separate multi-word controller names.</p>
  57. <?php else: ?>
  58. <p>
  59. 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.
  60. </p>
  61. <p class="error">
  62. <strong>Suggestion</strong>
  63. Create the class <em><?= h($class) ?>Controller</em> below in file: <?= h($path) ?>
  64. </p>
  65. <?php
  66. $code = <<<PHP
  67. <?php
  68. namespace {$namespace}\Controller{$prefixNs};
  69. use {$namespace}\Controller\AppController;
  70. class {$class}Controller extends AppController
  71. {
  72. }
  73. PHP;
  74. ?>
  75. <div class="code-dump"><?php highlight_string($code); ?></div>
  76. <?php endif; ?>
  77. <?php $this->end(); ?>