From 261ff6f2192e38091c5a659c3f61141c1cacd2cc Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 14 Mar 2007 18:28:36 +0000 Subject: [PATCH] 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 --- cake/libs/view/view.php | 51 ++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 9503bf4e4..63bb4abe4 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -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(); } }