Permalink
Browse files

NEW: Page types no longer require a controller, they can inherit the …

…parent page type's

Use ClassInfo::ancestry() instead of get_parent_class()

Fall back to ContentController by default
  • Loading branch information...
1 parent 3d9fc2c commit b6589ba9a94f2ba532813cc15be1df58c37d2c61 @kinglozzer kinglozzer committed Oct 23, 2013
Showing with 10 additions and 3 deletions.
  1. +10 −3 code/controllers/ModelAsController.php
@@ -16,9 +16,16 @@ class ModelAsController extends Controller implements NestedController {
* @param string $action
* @return ContentController
*/
- static public function controller_for(SiteTree $sitetree, $action = null) {
- if($sitetree->class == 'SiteTree') $controller = "ContentController";
- else $controller = "{$sitetree->class}_Controller";
+ public static function controller_for(SiteTree $sitetree, $action = null) {
+ if ($sitetree->class == 'SiteTree') {
+ $controller = "ContentController";
+ } else {
+ $ancestry = ClassInfo::ancestry($sitetree->class);
+ while ($class = array_pop($ancestry)) {
+ if (class_exists($class . "_Controller")) break;
+ }
+ $controller = ($class !== null) ? "{$class}_Controller" : "ContentController";
+ }
if($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action);

0 comments on commit b6589ba

Please sign in to comment.