ScaffoldView.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Scaffold.
  4. *
  5. * Automatic forms and actions generation for rapid web application development.
  6. *
  7. * PHP 5
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  10. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * For full copyright and license information, please see the LICENSE.txt
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  17. * @link http://cakephp.org CakePHP(tm) Project
  18. * @package Cake.View
  19. * @since Cake v 0.10.0.1076
  20. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  21. */
  22. App::uses('View', 'View');
  23. /**
  24. * ScaffoldView provides specific view file loading features for scaffolded views.
  25. *
  26. * @package Cake.View
  27. */
  28. class ScaffoldView extends View {
  29. /**
  30. * Override _getViewFileName Appends special scaffolding views in.
  31. *
  32. * @param string $name name of the view file to get.
  33. * @return string action
  34. * @throws MissingViewException
  35. */
  36. protected function _getViewFileName($name = null) {
  37. if ($name === null) {
  38. $name = $this->action;
  39. }
  40. $name = Inflector::underscore($name);
  41. $prefixes = Configure::read('Routing.prefixes');
  42. if (!empty($prefixes)) {
  43. foreach ($prefixes as $prefix) {
  44. if (strpos($name, $prefix . '_') !== false) {
  45. $name = substr($name, strlen($prefix) + 1);
  46. break;
  47. }
  48. }
  49. }
  50. if ($name === 'add' || $name === 'edit') {
  51. $name = 'form';
  52. }
  53. $scaffoldAction = 'scaffold.' . $name;
  54. if (!is_null($this->subDir)) {
  55. $subDir = strtolower($this->subDir) . DS;
  56. } else {
  57. $subDir = null;
  58. }
  59. $names[] = $this->viewPath . DS . $subDir . $scaffoldAction;
  60. $names[] = 'Scaffolds' . DS . $subDir . $name;
  61. $paths = $this->_paths($this->plugin);
  62. $exts = array($this->ext);
  63. if ($this->ext !== '.ctp') {
  64. $exts[] = '.ctp';
  65. }
  66. foreach ($exts as $ext) {
  67. foreach ($paths as $path) {
  68. foreach ($names as $name) {
  69. if (file_exists($path . $name . $ext)) {
  70. return $path . $name . $ext;
  71. }
  72. }
  73. }
  74. }
  75. if ($name === 'Scaffolds' . DS . $subDir . 'error') {
  76. return CAKE . 'View' . DS . 'Errors' . DS . 'scaffold_error.ctp';
  77. }
  78. throw new MissingViewException($paths[0] . $name . $this->ext);
  79. }
  80. }