mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Merging and updating revision number in VERSION file
Revision: [1694] Modified Controller::redirect(). Revision: [1693] Added ability to create your own custom view class that will override the core view. And example or this is located https://cakeforge.org/snippet/detail.php?type=snippet&id=6 Revision: [1690] fixed wrong operator used in Controller::redirect(); git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1695 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b19e1cd6cb
commit
6be00ac61a
4 changed files with 96 additions and 22 deletions
|
@ -6,4 +6,4 @@
|
||||||
// +---------------------------------------------------------------------------------------------------+ //
|
// +---------------------------------------------------------------------------------------------------+ //
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
0.10.4.1689_beta
|
0.10.4.1695_beta
|
|
@ -78,6 +78,31 @@ function loadModels ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads custom view class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function loadView ($viewClass)
|
||||||
|
{
|
||||||
|
if(!class_exists($viewClass))
|
||||||
|
{
|
||||||
|
$file = Inflector::underscore($viewClass).'.php';
|
||||||
|
if(file_exists(VIEWS.$file))
|
||||||
|
{
|
||||||
|
return require_once(VIEWS.$file);
|
||||||
|
}
|
||||||
|
elseif(file_exists(LIBS.'view'.DS.$file))
|
||||||
|
{
|
||||||
|
return require_once(LIBS.'view'.DS.$file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all controllers.
|
* Loads all controllers.
|
||||||
*
|
*
|
||||||
|
|
|
@ -172,6 +172,20 @@ class Controller extends Object
|
||||||
*/
|
*/
|
||||||
var $components = array();
|
var $components = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $view = 'View';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $_viewClass = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -281,11 +295,11 @@ class Controller extends Object
|
||||||
function redirect ($url)
|
function redirect ($url)
|
||||||
{
|
{
|
||||||
$this->autoRender = false;
|
$this->autoRender = false;
|
||||||
if(strpos($url, '/') == 0)
|
if(strpos($url, '/') !== 0)
|
||||||
{
|
{
|
||||||
$url = substr("$url", 1);
|
$url = '/'.$url;
|
||||||
}
|
}
|
||||||
header ('Location: '.$this->webroot.$url);
|
header ('Location: '.$this->base.$url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,7 +370,13 @@ class Controller extends Object
|
||||||
*/
|
*/
|
||||||
function render($action=null, $layout=null, $file=null)
|
function render($action=null, $layout=null, $file=null)
|
||||||
{
|
{
|
||||||
$view =& new View($this);
|
$viewClass = $this->view;
|
||||||
|
if($this->view != 'View' && !class_exists($viewClass))
|
||||||
|
{
|
||||||
|
$viewClass = $this->view.'View';
|
||||||
|
loadView($this->view);
|
||||||
|
}
|
||||||
|
$this->_viewClass =& new $viewClass($this);
|
||||||
if(!empty($this->modelNames))
|
if(!empty($this->modelNames))
|
||||||
{
|
{
|
||||||
foreach ($this->modelNames as $model)
|
foreach ($this->modelNames as $model)
|
||||||
|
@ -368,7 +388,7 @@ class Controller extends Object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->autoRender = false;
|
$this->autoRender = false;
|
||||||
return $view->render($action, $layout, $file);
|
return $this->_viewClass->render($action, $layout, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -180,6 +180,20 @@ class View extends Object
|
||||||
*/
|
*/
|
||||||
var $loaded = array();
|
var $loaded = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $ext = '.thtml';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $subDir = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -267,9 +281,9 @@ class View extends Object
|
||||||
foreach(array($this->name, 'errors') as $viewDir)
|
foreach(array($this->name, 'errors') as $viewDir)
|
||||||
{
|
{
|
||||||
$errorAction =Inflector::underscore($errorAction);
|
$errorAction =Inflector::underscore($errorAction);
|
||||||
if(file_exists(VIEWS.$viewDir.DS.$errorAction.'.thtml'))
|
if(file_exists(VIEWS.$viewDir.DS.$errorAction.$this->ext))
|
||||||
{
|
{
|
||||||
$missingViewFileName = VIEWS.$viewDir.DS.$errorAction.'.thtml';
|
$missingViewFileName = VIEWS.$viewDir.DS.$errorAction.$this->ext;
|
||||||
}
|
}
|
||||||
elseif(file_exists(LIBS.'view'.DS.'templates'.DS.$viewDir.DS.$errorAction.'.thtml'))
|
elseif(file_exists(LIBS.'view'.DS.'templates'.DS.$viewDir.DS.$errorAction.'.thtml'))
|
||||||
{
|
{
|
||||||
|
@ -293,7 +307,7 @@ class View extends Object
|
||||||
$controller = $this;
|
$controller = $this;
|
||||||
$controller->missingView = $viewFileName;
|
$controller->missingView = $viewFileName;
|
||||||
$controller->action = $action;
|
$controller->action = $action;
|
||||||
call_user_func_array(array(&$controller, 'missingView'), empty($params['pass'])? null: $params['pass']);
|
call_user_func_array(array('View', 'missingView'), empty($params['pass'])? null: $params['pass']);
|
||||||
$isFatal = isset($this->isFatal) ? $this->isFatal : false;
|
$isFatal = isset($this->isFatal) ? $this->isFatal : false;
|
||||||
if (!$isFatal)
|
if (!$isFatal)
|
||||||
{
|
{
|
||||||
|
@ -323,7 +337,14 @@ class View extends Object
|
||||||
|
|
||||||
if ($viewFileName && !$this->hasRendered)
|
if ($viewFileName && !$this->hasRendered)
|
||||||
{
|
{
|
||||||
$out = $this->_render($viewFileName, $this->_viewVars, 0);
|
if(substr($viewFileName, -5) === 'thtml')
|
||||||
|
{
|
||||||
|
$out = View::_render($viewFileName, $this->_viewVars, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$out = $this->_render($viewFileName, $this->_viewVars, 0);
|
||||||
|
}
|
||||||
if ($out !== false)
|
if ($out !== false)
|
||||||
{
|
{
|
||||||
if ($this->layout && $this->autoLayout)
|
if ($this->layout && $this->autoLayout)
|
||||||
|
@ -357,7 +378,7 @@ class View extends Object
|
||||||
*/
|
*/
|
||||||
function renderElement($name, $params=array())
|
function renderElement($name, $params=array())
|
||||||
{
|
{
|
||||||
$fn = ELEMENTS.$name.'.thtml';
|
$fn = ELEMENTS.$name.$this->ext;
|
||||||
|
|
||||||
if (!file_exists($fn))
|
if (!file_exists($fn))
|
||||||
{
|
{
|
||||||
|
@ -384,7 +405,16 @@ class View extends Object
|
||||||
if (is_file($layout_fn))
|
if (is_file($layout_fn))
|
||||||
{
|
{
|
||||||
$data_for_layout = array_merge($data_for_layout,$this->loaded); # load all view variables)
|
$data_for_layout = array_merge($data_for_layout,$this->loaded); # load all view variables)
|
||||||
$out = $this->_render($layout_fn, $data_for_layout, true, false);
|
|
||||||
|
if(substr($layout_fn, -5) === 'thtml')
|
||||||
|
{
|
||||||
|
$out = View::_render($layout_fn, $data_for_layout, true, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$out = $this->_render($layout_fn, $data_for_layout, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
if ($out === false)
|
if ($out === false)
|
||||||
{
|
{
|
||||||
$out = $this->_render($layout_fn, $data_for_layout, false);
|
$out = $this->_render($layout_fn, $data_for_layout, false);
|
||||||
|
@ -451,15 +481,15 @@ class View extends Object
|
||||||
{
|
{
|
||||||
$type = null;
|
$type = null;
|
||||||
}
|
}
|
||||||
$viewFileName = VIEWS.$this->viewPath.DS.$type.$action.'.thtml';
|
$viewFileName = VIEWS.$this->viewPath.DS.$this->subDir.$type.$action.$this->ext;
|
||||||
|
|
||||||
if(file_exists(VIEWS.$this->viewPath.DS.$type.$action.'.thtml'))
|
if(file_exists(VIEWS.$this->viewPath.DS.$this->subDir.$type.$action.$this->ext))
|
||||||
{
|
{
|
||||||
$viewFileName = VIEWS.$this->viewPath.DS.$type.$action.'.thtml';
|
$viewFileName = VIEWS.$this->viewPath.DS.$this->subDir.$type.$action.$this->ext;
|
||||||
}
|
}
|
||||||
elseif(file_exists(VIEWS.'errors'.DS.$type.$action.'.thtml'))
|
elseif(file_exists(VIEWS.'errors'.DS.$this->subDir.$type.$action.$this->ext))
|
||||||
{
|
{
|
||||||
$viewFileName = VIEWS.'errors'.DS.$type.$action.'.thtml';
|
$viewFileName = VIEWS.'errors'.DS.$this->subDir.$type.$action.$this->ext;
|
||||||
}
|
}
|
||||||
elseif(file_exists(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml'))
|
elseif(file_exists(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml'))
|
||||||
{
|
{
|
||||||
|
@ -470,7 +500,6 @@ class View extends Object
|
||||||
$viewFileName = LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml';
|
$viewFileName = LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$viewPath = explode(DS, $viewFileName);
|
$viewPath = explode(DS, $viewFileName);
|
||||||
$i = array_search('..', $viewPath);
|
$i = array_search('..', $viewPath);
|
||||||
unset($viewPath[$i-1]);
|
unset($viewPath[$i-1]);
|
||||||
|
@ -496,13 +525,13 @@ class View extends Object
|
||||||
{
|
{
|
||||||
$type = null;
|
$type = null;
|
||||||
}
|
}
|
||||||
$layoutFileName = LAYOUTS.$type."{$this->layout}.thtml";
|
$layoutFileName = LAYOUTS.$type."{$this->layout}$this->ext";
|
||||||
|
|
||||||
if(file_exists(LAYOUTS.$type."{$this->layout}.thtml"))
|
if(file_exists(LAYOUTS.$this->subDir.$type."{$this->layout}$this->ext"))
|
||||||
{
|
{
|
||||||
$layoutFileName = LAYOUTS.$type."{$this->layout}.thtml";
|
$layoutFileName = LAYOUTS.$this->subDir.$type."{$this->layout}$this->ext";
|
||||||
}
|
}
|
||||||
else if(file_exists(LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml"))
|
elseif(file_exists(LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml"))
|
||||||
{
|
{
|
||||||
$layoutFileName = LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml";
|
$layoutFileName = LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue