mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
commit
de7535d5a1
2 changed files with 24 additions and 1 deletions
|
@ -632,11 +632,11 @@ class Controller extends Object implements CakeEventListener {
|
|||
*/
|
||||
public function constructClasses() {
|
||||
$this->_mergeControllerVars();
|
||||
$this->Components->init($this);
|
||||
if ($this->uses) {
|
||||
$this->uses = (array)$this->uses;
|
||||
list(, $this->modelClass) = pluginSplit(current($this->uses));
|
||||
}
|
||||
$this->Components->init($this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -360,6 +360,13 @@ class TestComponent extends Object {
|
|||
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
@ -526,6 +533,22 @@ class ControllerTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue