From ef5650c034e8a1738f17bc517ed0f74fc60a5384 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Thu, 14 Jul 2011 01:30:52 -0430 Subject: [PATCH] Fixing ClassRegistry that was incorrectly checking class inheritance Fixing Model class that was incorrectly sending model names to be instantiated Fixing more FormHelper tests --- lib/Cake/Model/Model.php | 7 +++++-- .../Test/Case/View/Helper/FormHelperTest.php | 2 +- lib/Cake/Utility/ClassRegistry.php | 18 ++++++++++-------- lib/Cake/View/Helper/FormHelper.php | 7 +++---- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 3d7465cdc..eec4be3b8 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -702,10 +702,13 @@ class Model extends Object { } if (!isset($this->{$assoc}) || $this->{$assoc}->name !== $className) { - $model = array('class' => $plugin . '.' . $className, 'alias' => $assoc); + if ($plugin) { + $plugin .= '.'; + } + $model = array('class' => $plugin . $className, 'alias' => $assoc); $this->{$assoc} = ClassRegistry::init($model); if ($plugin) { - ClassRegistry::addObject($plugin . '.' . $className, $this->{$assoc}); + ClassRegistry::addObject($plugin . $className, $this->{$assoc}); } if ($assoc) { $this->tableToModel[$this->{$assoc}->table] = $assoc; diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 7ba1b5125..0a4fbceed 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -1882,7 +1882,7 @@ class FormHelperTest extends CakeTestCase { 'label' => array('for' => 'ObjectField'), 'Field', '/label', - 'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'), + 'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ModelField'), 'A message to you, Rudy', '/div' ); diff --git a/lib/Cake/Utility/ClassRegistry.php b/lib/Cake/Utility/ClassRegistry.php index 8f98452e7..c0ec403ab 100644 --- a/lib/Cake/Utility/ClassRegistry.php +++ b/lib/Cake/Utility/ClassRegistry.php @@ -135,16 +135,18 @@ class ClassRegistry { App::uses($plugin . 'AppModel', $pluginPath . 'Model'); App::uses($class, $pluginPath . 'Model'); - if (class_exists($class) && $class instanceof Model) { + if (class_exists($class)) { ${$class} = new $class($settings); + $$class = ($$class instanceof Mdoel) ? $$class : null; + } + if (!isset($$class) && $strict) { + return false; + } elseif ($plugin && class_exists($plugin . 'AppModel')) { + $appModel = $plugin . 'AppModel'; } else { - if ($strict) { - return false; - } elseif ($plugin && class_exists($plugin . 'AppModel')) { - $appModel = $plugin . 'AppModel'; - } else { - $appModel = 'AppModel'; - } + $appModel = 'AppModel'; + } + if (!empty($appModel)) { $settings['name'] = $class; ${$class} = new $appModel($settings); } diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 35792e0e6..aeb60136d 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -156,11 +156,10 @@ class FormHelper extends AppHelper { return $this->fieldset[$model]['key']; } - if (!isset($this->fieldset[$model]['fields'])) { - $fields = $this->fieldset[$model]['fields'] = $object->schema(); - } - if ($key === 'fields') { + if (!isset($this->fieldset[$model]['fields'])) { + $fields = $this->fieldset[$model]['fields'] = $object->schema(); + } if (empty($field)) { foreach ($object->hasAndBelongsToMany as $alias => $assocData) { $this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple');