Adding a check to the object before use

For some reason that I have not been able to figure out yet the object is
returned as null.  This is causing some exceptions when trying to access
properties that dont exist.

FatalErrorException: "Call to a member function getAssociated() on a non-object"

Test still pass with the added check.
This commit is contained in:
dogmatic69 2012-09-14 14:54:10 +01:00
parent 1fe791353f
commit 6f3e6c10a1

View file

@ -146,7 +146,7 @@ class FormHelper extends AppHelper {
));
} elseif (ClassRegistry::isKeySet($this->defaultModel)) {
$defaultObject = ClassRegistry::getObject($this->defaultModel);
if (in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) {
if ($defaultObject && in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) {
$object = $defaultObject->{$model};
}
} else {