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
This commit is contained in:
gwoo 2006-11-25 22:04:43 +00:00
parent 4320acdb96
commit 9e404b3ce3
3 changed files with 122 additions and 105 deletions

View file

@ -187,7 +187,7 @@ class Controller extends Object {
* *
* @var array * @var array
*/ */
var $ext = '.thtml'; var $ext = '.ctp';
/** /**
* Enter description here... * Enter description here...
* *
@ -887,10 +887,7 @@ class Controller extends Object {
if ($modelClass == null) { if ($modelClass == null) {
$modelClass = $this->modelClass; $modelClass = $this->modelClass;
} }
foreach($this->{$modelClass}->_tableInfo->value as $field) {
foreach($this->{$modelClass}->_tableInfo as $table) {
foreach($table as $field) {
if ('date' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_year'])) { if ('date' == $field['type'] && isset($this->data[$modelClass][$field['name'] . '_year'])) {
$newDate = $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'] . '_month'] . '-';
@ -940,7 +937,6 @@ class Controller extends Object {
} }
} }
} }
}
/** /**
* Handles automatic pagination of model records * Handles automatic pagination of model records
* *
@ -1028,7 +1024,9 @@ class Controller extends Object {
} }
extract(am(array('page' => 1, 'limit' => 20), $defaults, $options)); 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); $conditions = array($conditions, $scope);
} }
$results = $object->findAll($conditions, $fields, $order, $limit, $page, $recursive); $results = $object->findAll($conditions, $fields, $order, $limit, $page, $recursive);

View file

@ -102,17 +102,37 @@ class ThemeView extends View {
$file = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'elements' . DS . $name . $this->ext; $file = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'elements' . DS . $name . $this->ext;
$params = array_merge_recursive($params, $this->loaded); $params = array_merge_recursive($params, $this->loaded);
return $this->_render($file, array_merge($this->_viewVars, $params), false); 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)) { $paths = Configure::getInstance();
$file = ELEMENTS.$name.$this->ext; foreach($paths->viewPaths as $path) {
if (!file_exists($file)) { if (file_exists($file)) {
return "(Error rendering {$name})"; $params = array_merge_recursive($params, $this->loaded);
}
}
$params=array_merge_recursive($params, $this->loaded);
return $this->_render($file, array_merge($this->_viewVars, $params), false); 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);
}
}
return "(Error rendering Element: {$name})";
} }
/** /**
@ -141,19 +161,39 @@ class ThemeView extends View {
unset($action[$i]); unset($action[$i]);
$action='..' . DS . implode(DS, $action); $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) { foreach($paths->viewPaths as $path) {
if (file_exists($path . $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) { 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 $path . $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext;
return $viewFileName;
} elseif (file_exists($path . $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 $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext;
return $viewFileName; } 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')) { 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 . '.thtml')) { } elseif($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) {
} else { } else {
$viewFileName = $this->themePath . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; $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 (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)) { 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 APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext;
return $layoutFileName;
} elseif (file_exists(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 APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext;
return $layoutFileName; } 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")) { if (file_exists($this->themeLayout . $this->subDir . $type . $this->layout . $this->ext)) {
$layoutFileName = $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")) { } elseif (file_exists(LAYOUTS . $this->subDir . $type . $this->layout . $this->ext)) {
$layoutFileName = 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")) { } 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 { } else {
$layoutFileName = LAYOUTS . $type . "{$this->layout}$this->ext"; $layoutFileName = LAYOUTS . $type . $this->layout . $this->ext;
} }
return $layoutFileName; 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)));
}
}
} }
?> ?>

View file

@ -340,7 +340,7 @@ class View extends Object {
} else { } else {
$missingViewExists = false; $missingViewExists = false;
} }
echo $viewFileName;
if (!$missingViewExists || $isFatal) { if (!$missingViewExists || $isFatal) {
if (DEBUG) { if (DEBUG) {
trigger_error(sprintf(__("No template file for view %s (expected %s), create it first'"), $action, $viewFileName), E_USER_ERROR); trigger_error(sprintf(__("No template file for view %s (expected %s), create it first'"), $action, $viewFileName), E_USER_ERROR);
@ -613,17 +613,15 @@ class View extends Object {
if (!is_null($this->plugin)) { if (!is_null($this->plugin)) {
$viewFileName = 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;
if (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $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; 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)) { } elseif (file_exists($viewFileName)) {
return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext; return $viewFileName;
} elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . '.thtml')) { } 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'; 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')) { } 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'; return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . '.thtml';
} else { } else {
$viewFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $action . $this->ext;
return $this->cakeError('missingView', array(array( return $this->cakeError('missingView', array(array(
'className' => $this->name, 'className' => $this->name,
'action' => $action, 'action' => $action,
@ -631,7 +629,6 @@ class View extends Object {
'base' => $this->base))); 'base' => $this->base)));
} }
} }
foreach($paths->viewPaths as $path) { foreach($paths->viewPaths as $path) {
if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) { if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) {
return $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; return $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext;