Adding View::uuid() to generate DOM IDs, updating HTTP headers in View::error(), and fixing code formatting

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4610 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-03-14 18:28:36 +00:00
parent 5be52520c5
commit 261ff6f219

View file

@ -274,6 +274,12 @@ class View extends Object {
* @access protected
*/
var $__passedVars = array('viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot', 'helpers', 'here', 'layout', 'modelNames', 'name', 'pageTitle', 'layoutPath', 'viewPath', 'params', 'data', 'webservices', 'plugin', 'namedArgs', 'argSeparator', 'cacheAction');
/**
* List of generated DOM UUIDs
*
* @var array
*/
var $uuids = array();
/**
* Constructor
*
@ -290,10 +296,9 @@ class View extends Object {
if (!is_null($this->plugin)) {
$this->pluginPath = 'plugins'. DS . $this->plugin . DS;
$this->pluginPaths = array(
VIEWS . $this->pluginPath,
APP . $this->pluginPath . 'views' . DS,
);
VIEWS . $this->pluginPath,
APP . $this->pluginPath . 'views' . DS,
);
}
parent::__construct();
ClassRegistry::addObject('view', $this);
@ -538,6 +543,24 @@ class View extends Object {
$this->__scripts[$name] = $content;
}
}
/**
* Generates a unique, non-random DOM ID for an object, based on the object type and the target URL.
*
* @param string $object Type of object, i.e. 'form' or 'link'
* @param string $url The object's target URL
* @return string
* @access public
*/
function uuid($object, $url) {
$c = 1;
$hash = $object . substr(md5($object . Router::url($url)), 0, 10);
while (in_array($hash, $this->uuids)) {
$hash = $object . substr(md5($object . Router::url($url) . $c), 0, 10);
$c++;
}
$this->uuids[] = $hash;
return $hash;
}
/**
* @deprecated
*/
@ -588,10 +611,15 @@ class View extends Object {
* @param string $message Error message as a web page
*/
function error($code, $name, $message) {
header ("HTTP/1.0 {$code} {$name}");
print ($this->_render(VIEWS . 'layouts/error.thtml', array('code' => $code,
'name' => $name,
'message' => $message)));
header ("HTTP/1.1 {$code} {$name}");
print ($this->_render(
VIEWS . 'layouts/error.thtml',
array(
'code' => $code,
'name' => $name,
'message' => $message
)
));
}
/**************************************************************************
@ -815,9 +843,10 @@ class View extends Object {
}
if (!class_exists($helperCn)) {
$this->cakeError('missingHelperClass', array(array(
'helper' => $helper,
'file' => Inflector::underscore($helper) . '.php',
'base' => $this->base)));
'helper' => $helper,
'file' => Inflector::underscore($helper) . '.php',
'base' => $this->base
)));
exit();
}
}