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:
phpnut 2006-01-01 02:05:01 +00:00
parent b19e1cd6cb
commit 6be00ac61a
4 changed files with 96 additions and 22 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.4.1689_beta
0.10.4.1695_beta

View file

@ -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.
*

View file

@ -172,6 +172,20 @@ class Controller extends Object
*/
var $components = array();
/**
* Enter description here...
*
* @var unknown_type
*/
var $view = 'View';
/**
* Enter description here...
*
* @var unknown_type
*/
var $_viewClass = null;
/**
* Constructor.
*
@ -281,11 +295,11 @@ class Controller extends Object
function redirect ($url)
{
$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)
{
$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))
{
foreach ($this->modelNames as $model)
@ -368,7 +388,7 @@ class Controller extends Object
}
}
$this->autoRender = false;
return $view->render($action, $layout, $file);
return $this->_viewClass->render($action, $layout, $file);
}
/**

View file

@ -180,6 +180,20 @@ class View extends Object
*/
var $loaded = array();
/**
* Enter description here...
*
* @var array
*/
var $ext = '.thtml';
/**
* Enter description here...
*
* @var array
*/
var $subDir = null;
/**
* Constructor
*
@ -267,9 +281,9 @@ class View extends Object
foreach(array($this->name, 'errors') as $viewDir)
{
$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'))
{
@ -293,7 +307,7 @@ class View extends Object
$controller = $this;
$controller->missingView = $viewFileName;
$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;
if (!$isFatal)
{
@ -322,8 +336,15 @@ class View extends Object
}
if ($viewFileName && !$this->hasRendered)
{
if(substr($viewFileName, -5) === 'thtml')
{
$out = View::_render($viewFileName, $this->_viewVars, 0);
}
else
{
$out = $this->_render($viewFileName, $this->_viewVars, 0);
}
if ($out !== false)
{
if ($this->layout && $this->autoLayout)
@ -357,7 +378,7 @@ class View extends Object
*/
function renderElement($name, $params=array())
{
$fn = ELEMENTS.$name.'.thtml';
$fn = ELEMENTS.$name.$this->ext;
if (!file_exists($fn))
{
@ -384,7 +405,16 @@ class View extends Object
if (is_file($layout_fn))
{
$data_for_layout = array_merge($data_for_layout,$this->loaded); # load all view variables)
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)
{
$out = $this->_render($layout_fn, $data_for_layout, false);
@ -451,15 +481,15 @@ class View extends Object
{
$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'))
{
@ -470,7 +500,6 @@ class View extends Object
$viewFileName = LIBS.'view'.DS.'templates'.DS.$this->viewPath.DS.$type.$action.'.thtml';
}
$viewPath = explode(DS, $viewFileName);
$i = array_search('..', $viewPath);
unset($viewPath[$i-1]);
@ -496,11 +525,11 @@ class View extends Object
{
$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";
}
elseif(file_exists(LIBS.'view'.DS.'templates'.DS."layouts".DS.$type."{$this->layout}.thtml"))
{