missing_controller.php 3.1 KB

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