Browse Source

Fix partial matching of model name when autoloading.

ADmad 11 years ago
parent
commit
75e6b79c52
2 changed files with 13 additions and 3 deletions
  1. 3 3
      src/Controller/Controller.php
  2. 10 0
      tests/TestCase/Controller/ControllerTest.php

+ 3 - 3
src/Controller/Controller.php

@@ -300,14 +300,14 @@ class Controller implements EventListener {
 	}
 
 /**
- * Provides backwards compatibility to avoid problems with empty and isset to alias properties.
+ * Magic accessor for model autoloading.
  *
  * @param string $name Property name
  * @return bool
  */
 	public function __get($name) {
-		if (strpos($this->modelClass, $name) !== false) {
-			list($plugin, $class) = pluginSplit($this->modelClass, true);
+		list($plugin, $class) = pluginSplit($this->modelClass, true);
+		if ($class === $name) {
 			$this->loadModel($plugin . $class);
 			return $this->{$class};
 		}

+ 10 - 0
tests/TestCase/Controller/ControllerTest.php

@@ -241,8 +241,18 @@ class ControllerTest extends TestCase {
 		$request = new Request('controller_posts/index');
 		$response = $this->getMock('Cake\Network\Response');
 		$Controller = new Controller($request, $response);
+		$Controller->modelClass = 'SiteArticles';
+
+		$this->assertFalse($Controller->Articles);
+		$this->assertInstanceOf(
+			'Cake\ORM\Table',
+			$Controller->SiteArticles
+		);
+		unset($Controller->SiteArticles);
+
 		$Controller->modelClass = 'Articles';
 
+		$this->assertFalse($Controller->SiteArticles);
 		$this->assertInstanceOf(
 			'TestApp\Model\Table\ArticlesTable',
 			$Controller->Articles