From 9e404b3ce3e010944da01b9647e0acfc65ec6a1a Mon Sep 17 00:00:00 2001 From: gwoo Date: Sat, 25 Nov 2006 22:04:43 +0000 Subject: [PATCH] refactor of view paths refactor theme view paths fix cleanUpFields error, changed ext in controller to ctp, fix for paginate conditions and scope git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3970 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 98 ++++++++++++----------- cake/libs/view/theme.php | 116 +++++++++++++++++----------- cake/libs/view/view.php | 13 ++-- 3 files changed, 122 insertions(+), 105 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 958dd46be..f6516f80e 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -187,7 +187,7 @@ class Controller extends Object { * * @var array */ - var $ext = '.thtml'; + var $ext = '.ctp'; /** * Enter description here... * @@ -887,57 +887,53 @@ class Controller extends Object { if ($modelClass == null) { $modelClass = $this->modelClass; } + foreach($this->{$modelClass}->_tableInfo->value as $field) { + if ('date' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_year'])) { + $newDate = $this->data[$modelClass][$field['name'] . '_year'] . '-'; + $newDate .= $this->data[$modelClass][$field['name'] . '_month'] . '-'; + $newDate .= $this->data[$modelClass][$field['name'] . '_day']; + unset($this->data[$modelClass][$field['name'] . '_year']); + unset($this->data[$modelClass][$field['name'] . '_month']); + unset($this->data[$modelClass][$field['name'] . '_day']); + unset($this->data[$modelClass][$field['name'] . '_hour']); + unset($this->data[$modelClass][$field['name'] . '_min']); + unset($this->data[$modelClass][$field['name'] . '_meridian']); + $this->data[$modelClass][$field['name']] = $newDate; + $this->data[$modelClass][$field['name']] = $newDate; - foreach($this->{$modelClass}->_tableInfo as $table) { - foreach($table as $field) { + } elseif('datetime' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_year'])) { + $hour = $this->data[$modelClass][$field['name'] . '_hour']; - if ('date' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_year'])) { - $newDate = $this->data[$modelClass][$field['name'] . '_year'] . '-'; - $newDate .= $this->data[$modelClass][$field['name'] . '_month'] . '-'; - $newDate .= $this->data[$modelClass][$field['name'] . '_day']; - unset($this->data[$modelClass][$field['name'] . '_year']); - unset($this->data[$modelClass][$field['name'] . '_month']); - unset($this->data[$modelClass][$field['name'] . '_day']); - unset($this->data[$modelClass][$field['name'] . '_hour']); - unset($this->data[$modelClass][$field['name'] . '_min']); - unset($this->data[$modelClass][$field['name'] . '_meridian']); - $this->data[$modelClass][$field['name']] = $newDate; - $this->data[$modelClass][$field['name']] = $newDate; - - } elseif('datetime' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_year'])) { - $hour = $this->data[$modelClass][$field['name'] . '_hour']; - - if ($hour != 12 && (isset($this->data[$modelClass][$field['name'] . '_meridian']) && 'pm' == $this->data[$modelClass][$field['name'] . '_meridian'])) { - $hour = $hour + 12; - } - - $newDate = $this->data[$modelClass][$field['name'] . '_year'] . '-'; - $newDate .= $this->data[$modelClass][$field['name'] . '_month'] . '-'; - $newDate .= $this->data[$modelClass][$field['name'] . '_day'] . ' '; - $newDate .= $hour . ':' . $this->data[$modelClass][$field['name'] . '_min'] . ':00'; - unset($this->data[$modelClass][$field['name'] . '_year']); - unset($this->data[$modelClass][$field['name'] . '_month']); - unset($this->data[$modelClass][$field['name'] . '_day']); - unset($this->data[$modelClass][$field['name'] . '_hour']); - unset($this->data[$modelClass][$field['name'] . '_min']); - unset($this->data[$modelClass][$field['name'] . '_meridian']); - $this->data[$modelClass][$field['name']] = $newDate; - $this->data[$modelClass][$field['name']] = $newDate; - - } elseif('time' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_hour'])) { - $hour = $this->data[$modelClass][$field['name'] . '_hour']; - - if ($hour != 12 && (isset($this->data[$modelClass][$field['name'] . '_meridian']) && 'pm' == $this->data[$modelClass][$field['name'] . '_meridian'])) { - $hour = $hour + 12; - } - - $newDate = $hour . ':' . $this->data[$modelClass][$field['name'] . '_min'] . ':00'; - unset($this->data[$modelClass][$field['name'] . '_hour']); - unset($this->data[$modelClass][$field['name'] . '_min']); - unset($this->data[$modelClass][$field['name'] . '_meridian']); - $this->data[$modelClass][$field['name']] = $newDate; - $this->data[$modelClass][$field['name']] = $newDate; + if ($hour != 12 && (isset($this->data[$modelClass][$field['name'] . '_meridian']) && 'pm' == $this->data[$modelClass][$field['name'] . '_meridian'])) { + $hour = $hour + 12; } + + $newDate = $this->data[$modelClass][$field['name'] . '_year'] . '-'; + $newDate .= $this->data[$modelClass][$field['name'] . '_month'] . '-'; + $newDate .= $this->data[$modelClass][$field['name'] . '_day'] . ' '; + $newDate .= $hour . ':' . $this->data[$modelClass][$field['name'] . '_min'] . ':00'; + unset($this->data[$modelClass][$field['name'] . '_year']); + unset($this->data[$modelClass][$field['name'] . '_month']); + unset($this->data[$modelClass][$field['name'] . '_day']); + unset($this->data[$modelClass][$field['name'] . '_hour']); + unset($this->data[$modelClass][$field['name'] . '_min']); + unset($this->data[$modelClass][$field['name'] . '_meridian']); + $this->data[$modelClass][$field['name']] = $newDate; + $this->data[$modelClass][$field['name']] = $newDate; + + } elseif('time' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_hour'])) { + $hour = $this->data[$modelClass][$field['name'] . '_hour']; + + if ($hour != 12 && (isset($this->data[$modelClass][$field['name'] . '_meridian']) && 'pm' == $this->data[$modelClass][$field['name'] . '_meridian'])) { + $hour = $hour + 12; + } + + $newDate = $hour . ':' . $this->data[$modelClass][$field['name'] . '_min'] . ':00'; + unset($this->data[$modelClass][$field['name'] . '_hour']); + unset($this->data[$modelClass][$field['name'] . '_min']); + unset($this->data[$modelClass][$field['name'] . '_meridian']); + $this->data[$modelClass][$field['name']] = $newDate; + $this->data[$modelClass][$field['name']] = $newDate; } } } @@ -1028,7 +1024,9 @@ class Controller extends Object { } extract(am(array('page' => 1, 'limit' => 20), $defaults, $options)); - if ((is_array($scope) || is_string($scope)) && !empty($scope)) { + if (is_array($scope) && !empty($scope)) { + $conditions = am($conditions, $scope); + } elseif (is_string($scope)) { $conditions = array($conditions, $scope); } $results = $object->findAll($conditions, $fields, $order, $limit, $page, $recursive); diff --git a/cake/libs/view/theme.php b/cake/libs/view/theme.php index bca8afb76..bb29527bd 100644 --- a/cake/libs/view/theme.php +++ b/cake/libs/view/theme.php @@ -102,17 +102,37 @@ class ThemeView extends View { $file = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'elements' . DS . $name . $this->ext; $params = array_merge_recursive($params, $this->loaded); return $this->_render($file, array_merge($this->_viewVars, $params), false); + } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'elements' . DS . $this->theme . DS . $name . '.thtml')) { + $file = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'elements' . DS . $this->theme . DS . $name . '.thtml'; + $params = array_merge_recursive($params, $this->loaded); + return $this->_render($file, array_merge($this->_viewVars, $params), false); + } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'elements' . DS . $name . '.thtml')) { + $file = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'elements' . DS . $name . '.thtml'; + $params = array_merge_recursive($params, $this->loaded); + return $this->_render($file, array_merge($this->_viewVars, $params), false); } } - - if (!file_exists($file)) { - $file = ELEMENTS.$name.$this->ext; - if (!file_exists($file)) { - return "(Error rendering {$name})"; + + $paths = Configure::getInstance(); + foreach($paths->viewPaths as $path) { + if (file_exists($file)) { + $params = array_merge_recursive($params, $this->loaded); + return $this->_render($file, array_merge($this->_viewVars, $params), false); + } elseif (file_exists($path . 'elements' . DS . $name . $this->ext)) { + $file = $path . 'elements' . DS . $name . $this->ext; + $params = array_merge_recursive($params, $this->loaded); + return $this->_render($file, array_merge($this->_viewVars, $params), false); + } elseif (file_exists($this->themeElement . $name . '.thtml')) { + $file = $this->themeElement . $name . '.thtml'; + $params = array_merge_recursive($params, $this->loaded); + return $this->_render($file, array_merge($this->_viewVars, $params), false); + } elseif (file_exists($path . 'elements' . DS . $name . '.thtml')) { + $file = $path . 'elements' . DS . $name . '.thtml'; + $params = array_merge_recursive($params, $this->loaded); + return $this->_render($file, array_merge($this->_viewVars, $params), false); } } - $params=array_merge_recursive($params, $this->loaded); - return $this->_render($file, array_merge($this->_viewVars, $params), false); + return "(Error rendering Element: {$name})"; } /** @@ -141,19 +161,39 @@ class ThemeView extends View { unset($action[$i]); $action='..' . DS . implode(DS, $action); } + if (!is_null($this->plugin)) { + $viewFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->theme . DS . $this->viewPath . DS . $action . $this->ext; + if (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . $this->ext)) { + return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . $this->ext; + } elseif (file_exists($viewFileName)) { + return $viewFileName; + } elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . '.thtml')) { + return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . '.thtml'; + } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . '.thtml')) { + return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . '.thtml'; + } else { + return $this->cakeError('missingView', array(array( + 'className' => $this->name, + 'action' => $action, + 'file' => $viewFileName, + 'base' => $this->base))); + } + } foreach($paths->viewPaths as $path) { if (file_exists($path . $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) { - $viewFileName = $path . $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; - return $viewFileName; + return $path . $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; } elseif (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) { - $viewFileName = $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; - return $viewFileName; + return $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; + } elseif (file_exists($path . $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . '.thtml')) { + return $path . $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . '.thtml'; + } elseif (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $action . '.thtml')) { + return $path . $this->viewPath . DS . $this->subDir . $type . $action . '.thtml'; } } - if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.thtml')) { - } elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.thtml')) { + if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) { + } elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) { } else { $viewFileName = $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; } @@ -175,49 +215,31 @@ class ThemeView extends View { if (isset($this->plugin) && !is_null($this->plugin)) { if (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->theme . DS . $this->layout . $this->ext)) { - $layoutFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext; - return $layoutFileName; + return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext; } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext)) { - $layoutFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext; - return $layoutFileName; + return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext; + } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->theme . DS . $this->layout . '.thtml')) { + return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . '.thtml'; + } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . '.thtml')) { + return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . '.thtml'; } } - if (file_exists($this->themeLayout . $this->subDir . $type . "{$this->layout}$this->ext")) { - $layoutFileName = $this->themeLayout . $this->subDir . $type . "{$this->layout}$this->ext"; - } elseif (file_exists(LAYOUTS . $this->subDir . $type . "{$this->layout}$this->ext")) { - $layoutFileName = LAYOUTS . $this->subDir . $type . "{$this->layout}$this->ext"; - } elseif ($layoutFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . "layouts" . DS . $type . "{$this->layout}.thtml")) { + if (file_exists($this->themeLayout . $this->subDir . $type . $this->layout . $this->ext)) { + $layoutFileName = $this->themeLayout . $this->subDir . $type . $this->layout . $this->ext; + } elseif (file_exists(LAYOUTS . $this->subDir . $type . $this->layout . $this->ext)) { + $layoutFileName = LAYOUTS . $this->subDir . $type . $this->layout . $this->ext; + } elseif (file_exists($this->themeLayout . $this->subDir . $type . $this->layout . '.thtml')) { + $layoutFileName = $this->themeLayout . $this->subDir . $type . $this->layout . '.thtml'; + } elseif (file_exists(LAYOUTS . $this->subDir . $type . $this->layout . '.thtml')) { + $layoutFileName = LAYOUTS . $this->subDir . $type . $this->layout . '.thtml'; + }elseif ($layoutFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . $this->layout . '.ctp')) { } else { - $layoutFileName = LAYOUTS . $type . "{$this->layout}$this->ext"; + $layoutFileName = LAYOUTS . $type . $this->layout . $this->ext; } return $layoutFileName; } - -/** - * Enter description here... - * - * @param unknown_type $action - * @param unknown_type $layout - * @return unknown - */ - function pluginView($action, $layout) { - $viewFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->theme . DS . $this->viewPath . DS . $action . $this->ext; - - if (file_exists($viewFileName)) { - $this->render($action, $layout, $viewFileName); - } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext)) { - $viewFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext; - $this->render($action, $layout, $viewFileName); - } else{ - return $this->cakeError('missingView', array(array( - 'className' => $this->controller->name, - 'action' => $action, - 'file' => $viewFileName, - 'base' => $this->base))); - } - } } ?> \ No newline at end of file diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index ebb52c779..c3f620d57 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -340,7 +340,7 @@ class View extends Object { } else { $missingViewExists = false; } - + echo $viewFileName; if (!$missingViewExists || $isFatal) { if (DEBUG) { trigger_error(sprintf(__("No template file for view %s (expected %s), create it first'"), $action, $viewFileName), E_USER_ERROR); @@ -430,7 +430,7 @@ class View extends Object { */ function renderLayout($content_for_layout) { $layout_fn = $this->_getLayoutFileName(); - + if (DEBUG > 2 && $this->controller != null) { $debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . 'dump.ctp', array('controller' => $this->controller), false); } else { @@ -613,17 +613,15 @@ class View extends Object { if (!is_null($this->plugin)) { $viewFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext; - if (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . $this->ext)) { return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . $this->ext; - } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext)) { - return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext; + } elseif (file_exists($viewFileName)) { + return $viewFileName; } elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . '.thtml')) { return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . '.thtml'; } elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . '.thtml')) { return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . '.thtml'; } else { - $viewFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext; return $this->cakeError('missingView', array(array( 'className' => $this->name, 'action' => $action, @@ -631,7 +629,6 @@ class View extends Object { 'base' => $this->base))); } } - foreach($paths->viewPaths as $path) { if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) { return $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; @@ -639,7 +636,7 @@ class View extends Object { return $path . $this->viewPath . DS . $this->subDir . $type . $action . '.thtml'; } } - + if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) { } elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) { } else {