Skip to content

Commit

Permalink
Fix plugin models not being lazy loaded via __get.
Browse files Browse the repository at this point in the history
Refs #3682
  • Loading branch information
markstory committed Jun 10, 2014
1 parent 3d40307 commit d4a5fb7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -310,7 +310,7 @@ public function addComponent($name, array $config = []) {
* @return bool
*/
public function __get($name) {
if ($name === $this->modelClass) {
if (strpos($this->modelClass, $name) !== false) {
list($plugin, $class) = pluginSplit($name, true);
if (!$plugin) {
$plugin = $this->plugin ? $this->plugin . '.' : null;
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -303,13 +303,16 @@ public function testConstructSetModelClass() {
$response = new Response();
$controller = new \TestApp\Controller\PostsController($request, $response);
$this->assertEquals('Posts', $controller->modelClass);
$this->assertInstanceOf('Cake\ORM\Table', $controller->Posts);

$controller = new \TestApp\Controller\Admin\PostsController($request, $response);
$this->assertEquals('Posts', $controller->modelClass);
$this->assertInstanceOf('Cake\ORM\Table', $controller->Posts);

$request->params['plugin'] = 'TestPlugin';
$controller = new \TestPlugin\Controller\Admin\CommentsController($request, $response);
$this->assertEquals('TestPlugin.Comments', $controller->modelClass);
$this->assertInstanceOf('Cake\ORM\Table', $controller->Comments);
}

/**
Expand Down

0 comments on commit d4a5fb7

Please sign in to comment.