public function getNestedController()
 {
     if ($this->urlParams['URLSegment']) {
         $SQL_URLSegment = Convert::raw2sql($this->urlParams['URLSegment']);
         if (Translatable::is_enabled()) {
             $child = Translatable::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
         } else {
             $child = DataObject::get_one("SiteTree", "URLSegment = '{$SQL_URLSegment}'");
         }
         if (!$child) {
             $child = $this->get404Page();
         }
         if ($child) {
             if (isset($_REQUEST['debug'])) {
                 Debug::message("Using record #{$child->ID} of type {$child->class} with URL {$this->urlParams['URLSegment']}");
             }
             $controllerClass = "{$child->class}_Controller";
             if ($this->urlParams['Action'] && ClassInfo::exists($controllerClass . '_' . $this->urlParams['Action'])) {
                 $controllerClass = $controllerClass . '_' . $this->urlParams['Action'];
             }
             if (ClassInfo::exists($controllerClass)) {
                 $controller = new $controllerClass($child);
             } else {
                 $controller = $child;
             }
             $controller->setURLParams($this->urlParams);
             return $controller;
         } else {
             die("The requested page couldn't be found.");
         }
     } else {
         user_error("ModelAsController not geting a URLSegment.  It looks like the site isn't redirecting to home", E_USER_ERROR);
     }
 }
Beispiel #2
0
 static function currentPage()
 {
     if (isset(Director::$urlParams['URLSegment'])) {
         $SQL_urlSegment = Convert::raw2sql(Director::$urlParams['URLSegment']);
         if (Translatable::is_enabled()) {
             return Translatable::get_one("SiteTree", "URLSegment = '{$SQL_urlSegment}'");
         } else {
             return DataObject::get_one("SiteTree", "URLSegment = '{$SQL_urlSegment}'");
         }
     } else {
         return Controller::curr();
     }
 }