Skip to content

Commit

Permalink
Fix: Incorrect model being used as Controller::$modelClass
Browse files Browse the repository at this point in the history
We cannot be sure that Controller::$uses have not been iterated, so
reset the array to use the first value.
  • Loading branch information
rchavik committed May 24, 2013
1 parent ca1f9e8 commit a63b54c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Controller.php
Expand Up @@ -634,7 +634,7 @@ public function constructClasses() {
$this->_mergeControllerVars();
if ($this->uses) {
$this->uses = (array)$this->uses;
list(, $this->modelClass) = pluginSplit(current($this->uses));
list(, $this->modelClass) = pluginSplit(reset($this->uses));
}
$this->Components->init($this);
return true;
Expand Down
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/Controller/ControllerMergeVarsTest.php
Expand Up @@ -250,4 +250,17 @@ public function testMergeVarsNotGreedy() {

$this->assertFalse(isset($Controller->Session));
}

/**
* Ensure that $modelClass is correct even when Controller::$uses
* has been iterated, eg: by a Component, or event handlers.
*/
public function testMergeVarsModelClass() {
$Controller = new MergeVariablescontroller();
$Controller->uses = array('Test', 'TestAlias');
$lastModel = end($Controller->uses);
$Controller->constructClasses();
$this->assertEquals($Controller->uses[0], $Controller->modelClass);
}

}

0 comments on commit a63b54c

Please sign in to comment.