Skip to content
This repository
Browse code

extract the validationErrors logic

  • Loading branch information...
commit 20820d5dad130e3d229d11ce029ffaedf275327d 1 parent ec7ec73
Andy Dawson authored July 02, 2012

Showing 1 changed file with 27 additions and 11 deletions. Show diff stats Hide diff stats

  1. 38  lib/Cake/Controller/Controller.php
38  lib/Cake/Controller/Controller.php
@@ -940,17 +940,7 @@ public function render($view = null, $layout = null) {
940 940
 		}
941 941
 
942 942
 		$View = new $viewClass($this);
943  
-
944  
-		$models = ClassRegistry::keys();
945  
-		foreach ($models as $currentModel) {
946  
-			$currentObject = ClassRegistry::getObject($currentModel);
947  
-			if (is_a($currentObject, 'Model')) {
948  
-				$className = get_class($currentObject);
949  
-				list($plugin) = pluginSplit(App::location($className));
950  
-				$this->request->params['models'][$currentObject->alias] = compact('plugin', 'className');
951  
-				$View->validationErrors[$currentObject->alias] =& $currentObject->validationErrors;
952  
-			}
953  
-		}
  943
+		$View->validationErrors = $this->_validationErrors();
954 944
 
955 945
 		$this->autoRender = false;
956 946
 		$this->View = $View;
@@ -1225,4 +1215,30 @@ protected function _scaffoldError($method) {
1225 1215
 		return $this->scaffoldError($method);
1226 1216
 	}
1227 1217
 
  1218
+/**
  1219
+ * _validationErrors
  1220
+ *
  1221
+ * Get all validation errors for the current request
  1222
+ *
  1223
+ * @return array
  1224
+ */
  1225
+	protected function _validationErrors() {
  1226
+		$return = array();
  1227
+
  1228
+		$models = ClassRegistry::keys();
  1229
+		foreach ($models as $model) {
  1230
+			$object = ClassRegistry::getObject($model);
  1231
+			if (!is_a($object, 'Model')) {
  1232
+				continue;
  1233
+			}
  1234
+			$className = get_class($object);
  1235
+			if (array_key_exists($object->alias, $return)) {
  1236
+				continue;
  1237
+			}
  1238
+			list($plugin) = pluginSplit(App::location($className));
  1239
+			$return[$object->alias] =& $object->validationErrors;
  1240
+		}
  1241
+		return $return;
  1242
+	}
  1243
+
1228 1244
 }

0 notes on commit 20820d5

Please sign in to comment.
Something went wrong with that request. Please try again.