Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Project\Model;
- use SilverStripe\Core\ClassInfo;
- use SilverStripe\CMS\Model\SiteTree;
- use App\Project\Control\PageController;
- class Page extends SiteTree
- {
- /**
- * Returns the controller class for this page. If a subclass of the page
- * controller exists, use that. Otherwise default to the base namespaced
- * controller.
- *
- * This is required as the SiteTree getControllerName doesn't handle cross
- * namespace (i.e \Model\ vs \Control).
- */
- public function getControllerName()
- {
- $current = static::class;
- $ancestry = ClassInfo::ancestry($current);
- $controller = null;
- while ($class = array_pop($ancestry)) {
- if ($class == self::class) {
- break;
- }
- if (class_exists($candidate = sprintf('%sController', $class))) {
- $controller = $candidate;
- break;
- }
- $candidate = sprintf('%sController', str_replace('\\Model\\', '\\Control\\', $class));
- if (class_exists($candidate)) {
- $controller = $candidate;
- break;
- }
- }
- if ($controller) {
- return $controller;
- }
- return PageController::class;
- }
- }
Add Comment
Please, Sign In to add comment