Skip to content

Loading…

Fixing improper controller property inheritage when a controller extends... #1077

Closed
wants to merge 1 commit into from

2 participants

@burzum
CakePHP member

... another controller

@markstory markstory commented on the diff
lib/Cake/Controller/Controller.php
((5 lines not shown))
if ($this->name === null) {
- $this->name = substr(get_class($this), 0, -10);
+ $this->name = $name;
+ } elseif ($name !== $this->name) {
+ $this->name = $name;
}
@markstory CakePHP member

This will break existing applications that expect the current behavior. I don't think its a good idea to just override user set values because they don't strictly follow conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@markstory
CakePHP member

For the reasons explained in the related lighthouse ticket I think this shouldn't change.

@markstory markstory closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2013
  1. Fixing improper controller property inheritage when a controller exte…

    Florian Krämer committed
    …nds another controller
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 1 deletion.
  1. +4 −1 lib/Cake/Controller/Controller.php
  2. +21 −0 lib/Cake/Test/Case/Controller/ControllerTest.php
View
5 lib/Cake/Controller/Controller.php
@@ -315,8 +315,11 @@ class Controller extends Object implements CakeEventListener {
* @param CakeResponse $response Response object for this controller.
*/
public function __construct($request = null, $response = null) {
+ $name = substr(get_class($this), 0, -10);
if ($this->name === null) {
- $this->name = substr(get_class($this), 0, -10);
+ $this->name = $name;
+ } elseif ($name !== $this->name) {
+ $this->name = $name;
}
@markstory CakePHP member

This will break existing applications that expect the current behavior. I don't think its a good idea to just override user set values because they don't strictly follow conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if ($this->viewPath == null) {
View
21 lib/Cake/Test/Case/Controller/ControllerTest.php
@@ -129,6 +129,10 @@ class ControllerCommentsController extends ControllerTestAppController {
protected $_mergeParent = 'ControllerTestAppController';
}
+class ControllerTwoCommentsController extends ControllerCommentsController {
+
+}
+
/**
* ControllerComment class
*
@@ -1438,4 +1442,21 @@ public function testInvokeActionReturnValue() {
$this->assertEquals('I am from the controller.', $result);
}
+/**
+ * test invoking controller methods.
+ *
+ * @return void
+ */
+ public function testCorrectPropertyInitializationForInheritedControllers() {
+ $url = new CakeRequest('test/returner/');
+ $url->addParams(array(
+ 'controller' => 'test_controller',
+ 'action' => 'returner',
+ 'pass' => array()
+ ));
+ $response = $this->getMock('CakeResponse');
+ $Controller = new ControllerTwoCommentsController($url, $response);
+ $this->assertEqual($Controller->modelClass, 'ControllerTwoComment');
+ }
+
}
Something went wrong with that request. Please try again.