Skip to content
Browse files

Documentation and code cleaning, this commit means that the FormHelpe…

…r is now fully able to locate models even though lazy loading is used in the controller, closes #1690
  • Loading branch information...
1 parent b16a5f2 commit 84aba009e7fcc43c50b2df65c560ed5ec3ec65a3 @lorenzo lorenzo committed
Showing with 28 additions and 1 deletion.
  1. +28 −1 lib/Cake/View/Helper/FormHelper.php
View
29 lib/Cake/View/Helper/FormHelper.php
@@ -96,6 +96,7 @@ class FormHelper extends AppHelper {
* @access protected
*/
protected $_inputDefaults = array();
+
/**
* An array of fieldnames that have been excluded from
* the Token hash used by SecurityComponent's validatePost method
@@ -106,6 +107,12 @@ class FormHelper extends AppHelper {
*/
protected $_unlockedFields = array();
+/**
+ * Holds the model references already loaded by this helper
+ * product of trying to inspect them out of field names
+ *
+ * @var array
+ */
protected $_models = array();
/**
@@ -146,6 +153,25 @@ protected function _getModel($model) {
return $object;
}
+/**
+ * Inspects the model properties to extract information from them.
+ * Currently it can extract information from the the fields, the primary key and required fields
+ *
+ * The $key parameter accepts the following list of values:
+ *
+ * - key: Returns the name of the primary key for the model
+ * - fields: Returns the model schema
+ * - validates: returns the list of fields that are required
+ *
+ * If the $field parameter is passed if will return the information for that sole field.
+ *
+ * `$this->_introspectModel('Post', 'fields', 'title');` will return the schema information for title column
+ *
+ * @param string $model name of the model to extract information from
+ * @param string $key name of the special information key to obtain (key, fields, validates)
+ * @param string $field name of the model field to get information from
+ * @return mixed information extracted for the special key and field in a model
+ */
protected function _introspectModel($model, $key, $field = null) {
$object = $this->_getModel($model);
if (!$object) {
@@ -275,12 +301,13 @@ public function create($model = null, $options = array()) {
$model = false;
}
+ $key = null;
if ($model !== false) {
$object = $this->_getModel($model);
+ $key = $this->_introspectModel($model, 'key');
}
$this->setEntity($model, true);
- $key = $this->_introspectModel($model, 'key');
if ($model !== false && $key) {
$recordExists = (
isset($this->request->data[$model]) &&

0 comments on commit 84aba00

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