コード例 #1
0
 /**
  * get a controller
  * get the controller to use by the URL and the file routes.xml
  * @return object instance of a controller object
  */
 public function getController()
 {
     $router = new \library\router();
     // try to get the route corresponding to the URL
     // if the getRoute() method can't find the route, call error404 method
     try {
         $matchedRoute = $router->getRoute($this->httpRequest->requestUrl());
     } catch (\RuntimeException $e) {
         $this->httpResponse->redirect404();
     }
     // add the variables of the route to the GET session
     $_GET = array_merge($_GET, $matchedRoute->getVars());
     // run the controller found in the route
     preg_match_all('/([\\w]*)\\\\([\\w]*)$/', $matchedRoute->getModule(), $modules);
     if (!isset($modules[2][0])) {
         $controller = 'applications\\modules\\' . $matchedRoute->getModule() . '\\' . $matchedRoute->getModule() . 'Controller';
     } else {
         $controller = 'applications\\modules\\' . $modules[1][0] . '\\' . $modules[2][0] . 'Controller';
     }
     return new $controller($this, $matchedRoute->getModule(), $matchedRoute->getAction());
 }
コード例 #2
0
 /**
  * get the controller to call with the current URL.
  * @return object controller
  */
 public function getController()
 {
     //instanciate the router.
     $router = new \library\router();
     // try to get the route corresponding to the URL and return the associate controller.
     try {
         //get the route.
         $matchedRoute = $router->getRoute($this->httpRequest->requestUrl());
         $_GET = array_merge($_GET, $matchedRoute->getVars());
         // define the controller of the route.
         preg_match_all('/([\\w]*)\\\\([\\w]*)$/', $matchedRoute->getModule(), $modules);
         if (!isset($modules[2][0])) {
             $controller = 'applications\\modules\\' . $matchedRoute->getModule() . '\\' . $matchedRoute->getModule() . 'Controller';
         } else {
             $controller = 'applications\\modules\\' . $modules[1][0] . '\\' . $modules[2][0] . 'Controller';
         }
         return new $controller($this, $matchedRoute->getModule(), $matchedRoute->getAction());
     } catch (\RuntimeException $e) {
         if (ENABLE_REDIRECT_404 == 1) {
             $this->httpResponse->redirect404();
         }
     }
 }