Skip to content
Permalink
Browse files

Fix partial matching of model name when autoloading.

  • Loading branch information...
ADmad committed Sep 4, 2014
1 parent 39aaadf commit 75e6b79c52a0952a6fcd5de401e53ad79e9ab9f7
Showing with 13 additions and 3 deletions.
  1. +3 −3 src/Controller/Controller.php
  2. +10 −0 tests/TestCase/Controller/ControllerTest.php
@@ -300,14 +300,14 @@ public function addComponent($name, array $config = []) {
}
/**
* 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};
}
@@ -241,8 +241,18 @@ public function testTableAutoload() {
$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

0 comments on commit 75e6b79

Please sign in to comment.
You can’t perform that action at this time.