Refactoring loading plugin views and layouts.

Plugin templates can be overridden in the app/views/plugins/$plugin/$viewPath directory
If template is not found in this directory or the app/plugins/$plugin/views/$viewPath a missing 
view error will be rendered

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3966 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-11-25 19:58:16 +00:00
parent 0c0ba050cb
commit 76394b643f

View file

@ -301,10 +301,6 @@ class View extends Object {
$viewFileName = $this->_getViewFileName($action); $viewFileName = $this->_getViewFileName($action);
} }
if (!is_null($this->plugin) && is_null($file)) {
return $this->pluginView($action, $layout);
}
if (!is_file($viewFileName) && !fileExistsInPath($viewFileName) || $viewFileName === '/' || $viewFileName === '\\') { if (!is_file($viewFileName) && !fileExistsInPath($viewFileName) || $viewFileName === '/' || $viewFileName === '\\') {
if (strpos($action, 'missingAction') !== false) { if (strpos($action, 'missingAction') !== false) {
$errorAction = 'missingAction'; $errorAction = 'missingAction';
@ -609,6 +605,26 @@ class View extends Object {
$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->viewPath . DS . $action . $this->ext;
if (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . $this->ext)) {
$viewFileName = APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $action . $this->ext;
return $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;
return $viewFileName;
} 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->viewPath . DS . $this->subDir . $type . $action . $this->ext)) { if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext)) {
$viewFileName = $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext; $viewFileName = $path . $this->viewPath . DS . $this->subDir . $type . $action . $this->ext;
@ -642,12 +658,18 @@ class View extends Object {
$this->layoutPath = $this->layoutPath . DS; $this->layoutPath = $this->layoutPath . DS;
} }
if (isset($this->plugin) && !is_null($this->plugin)) { if (!is_null($this->plugin)) {
if (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext)) { if (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . 'layouts' . DS . $this->subDir . $type . $action . $this->ext)) {
$layoutFileName = APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . 'layouts' . DS . $this->subDir . $type . $action . $this->ext;
return $layoutFileName;
} 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; $layoutFileName = APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . 'layouts' . DS . $this->layout . $this->ext;
return $layoutFileName; return $layoutFileName;
} }
} }
$paths = Configure::getInstance(); $paths = Configure::getInstance();
foreach($paths->viewPaths as $path) { foreach($paths->viewPaths as $path) {
@ -804,28 +826,6 @@ class View extends Object {
return $loaded; return $loaded;
} }
/**
* 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->viewPath . DS . $action . $this->ext;
if (file_exists($viewFileName)) {
$this->render($action, $layout, $viewFileName);
} else {
return $this->cakeError('missingView', array(array(
'className' => $this->name,
'action' => $action,
'file' => $viewFileName,
'base' => $this->base
)));
}
}
function renderCache($filename, $timeStart) { function renderCache($filename, $timeStart) {
ob_start(); ob_start();
include ($filename); include ($filename);