Browse Source

Merge pull request #7064 from cakephp/issue-7061

Fix notice error when reading array values.
José Lorenzo Rodríguez 10 years ago
parent
commit
7af3fa1e60
2 changed files with 8 additions and 1 deletions
  1. 2 1
      src/View/Form/EntityContext.php
  2. 6 0
      tests/TestCase/View/Form/EntityContextTest.php

+ 2 - 1
src/View/Form/EntityContext.php

@@ -223,7 +223,8 @@ class EntityContext implements ContextInterface
         if ($entity instanceof EntityInterface) {
             return $entity->get(array_pop($parts));
         } elseif (is_array($entity)) {
-            return $entity[array_pop($parts)];
+            $key = array_pop($parts);
+            return isset($entity[$key]) ? $entity[$key] : null;
         }
         return null;
     }

+ 6 - 0
tests/TestCase/View/Form/EntityContextTest.php

@@ -477,6 +477,12 @@ class EntityContextTest extends TestCase
 
         $result = $context->val('tag.name');
         $this->assertEquals($row->tag['name'], $result);
+
+        $result = $context->val('tag.nope');
+        $this->assertNull($result);
+
+        $result = $context->val('author.roles.3');
+        $this->assertNull($result);
     }
 
     /**