mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
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
This commit is contained in:
parent
3d9fc2cc4c
commit
b6589ba9a9
@ -16,9 +16,16 @@ class ModelAsController extends Controller implements NestedController {
|
|||||||
* @param string $action
|
* @param string $action
|
||||||
* @return ContentController
|
* @return ContentController
|
||||||
*/
|
*/
|
||||||
static public function controller_for(SiteTree $sitetree, $action = null) {
|
public static function controller_for(SiteTree $sitetree, $action = null) {
|
||||||
if($sitetree->class == 'SiteTree') $controller = "ContentController";
|
if ($sitetree->class == 'SiteTree') {
|
||||||
else $controller = "{$sitetree->class}_Controller";
|
$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))) {
|
if($action && class_exists($controller . '_' . ucfirst($action))) {
|
||||||
$controller = $controller . '_' . ucfirst($action);
|
$controller = $controller . '_' . ucfirst($action);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user