PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Cake/View/ScaffoldView.php

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