Merge pull request #1282 from dereuromark/master-model-class

$this->modelClass needs to be correct prior to the components init()
This commit is contained in:
Mark Story 2013-05-14 08:55:56 -07:00
commit de7535d5a1
2 changed files with 24 additions and 1 deletions

View file

@ -632,11 +632,11 @@ class Controller extends Object implements CakeEventListener {
*/ */
public function constructClasses() { public function constructClasses() {
$this->_mergeControllerVars(); $this->_mergeControllerVars();
$this->Components->init($this);
if ($this->uses) { if ($this->uses) {
$this->uses = (array)$this->uses; $this->uses = (array)$this->uses;
list(, $this->modelClass) = pluginSplit(current($this->uses)); list(, $this->modelClass) = pluginSplit(current($this->uses));
} }
$this->Components->init($this);
return true; return true;
} }

View file

@ -360,6 +360,13 @@ class TestComponent extends Object {
class Test2Component extends TestComponent { class Test2Component extends TestComponent {
public $model;
public function __construct(ComponentCollection $collection, $settings) {
$this->controller = $collection->getController();
$this->model = $this->controller->modelClass;
}
public function beforeRender(Controller $controller) { public function beforeRender(Controller $controller) {
return false; return false;
} }
@ -526,6 +533,22 @@ class ControllerTest extends CakeTestCase {
$this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost')); $this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost'));
} }
/**
* testConstructClassesWithComponents method
*
* @return void
*/
public function testConstructClassesWithComponents() {
$Controller = new TestPluginController(new CakeRequest(), new CakeResponse());
$Controller->uses = array('NameTest');
$Controller->components[] = 'Test2';
$Controller->constructClasses();
$this->assertEquals('NameTest', $Controller->Test2->model);
$this->assertEquals('Name', $Controller->NameTest->name);
$this->assertEquals('Name', $Controller->NameTest->alias);
}
/** /**
* testAliasName method * testAliasName method
* *