Example #1
0
 /**
  *
  * @param Ajde_Core_Route $route
  * @return Ajde_Controller
  */
 public static function fromRoute(Route $route)
 {
     if ($controller = $route->getController()) {
         $moduleController = ucfirst($route->getModule()) . ucfirst($controller) . 'Controller';
     } else {
         $moduleController = ucfirst($route->getModule()) . 'Controller';
     }
     if (!Autoloader::exists($moduleController)) {
         // Prevent resursive 404 routing
         if (isset(Config::getInstance()->responseCodeRoute[Response::RESPONSE_TYPE_NOTFOUND])) {
             $notFoundRoute = new Route(Config::getInstance()->responseCodeRoute[Response::RESPONSE_TYPE_NOTFOUND]);
             if ($route->buildRoute() == $notFoundRoute->buildRoute()) {
                 Response::setResponseType(404);
                 die('<h2>Ouch, something broke.</h2><p>This is serious. We tried to give you a nice error page, but even that failed.</p><button onclick="location.href=\'' . Config::get('site_root') . '\';">Go back to homepage</button>');
             }
         }
         if (Autoloader::exists('Ajde_Exception')) {
             $exception = new Routing("Controller {$moduleController} for module {$route->getModule()} not found", 90008);
         } else {
             // Normal exception here to prevent [Class 'Ajde_Exception' not found] errors...
             $exception = new Exception("Controller {$moduleController} for module {$route->getModule()} not found");
         }
         Ajde::routingError($exception);
     }
     $controller = new $moduleController($route->getAction(), $route->getFormat());
     $controller->_route = $route;
     foreach ($route->values() as $part => $value) {
         $controller->set($part, $value);
     }
     return $controller;
 }