예제 #1
0
 public static function launch(&$request)
 {
     $response = new Response();
     $params =& $request->getParams();
     // Si app/controller/action vide => 404
     if (empty($params['module']) || empty($params['controller']) || empty($params['action'])) {
         $response->body = 'URL incompléte';
         $response->send404();
         return $response;
     }
     $moduleName = Url::toClass($params['module']);
     $controllerName = Url::toClass($params['controller']);
     $actionName = Url::toClass($params['action']);
     // Et on lance
     $controller = '\\App\\Modules\\' . $moduleName . '\\Controller\\' . $controllerName . 'Controller';
     if (!class_exists($controller)) {
         $response->body = 'Controleur ' . $controller . ' introuvable';
         $response->send404();
     }
     $oController = new $controller($request, $response);
     if (!method_exists($oController, $actionName)) {
         $response->body = 'Action ' . $actionName . ' introuvable';
         $response->send404();
         return $response;
     }
     $response = $oController->runAction($actionName);
     return $response;
 }
예제 #2
0
 /**
  * Affichage de vues partielles dans la vue
  * @param unknown_type $template
  * @param unknown_type $data
  * @return Ambigous <void, string>
  */
 public function render_partial($template, $data = array())
 {
     $template = Url::selector($template, array('module' => $this->params['module'], 'controller' => $this->params['controller']));
     // Nouveau objet, pour ne pas casser la construction de la vue principale
     //$template['action'] = '_'.$template['action'];
     $partialView = new View($this->controller);
     return $partialView->render($template, $data);
     //return $this->render($template, $data);
 }
예제 #3
0
 /**
  * Notre redirecteur
  * @return
  * @param $params Object
  * @deprecated
  */
 public function redirect_to($params, array $options = array())
 {
     // Tableau de params, dont controller et action
     if (is_array($params)) {
         if (empty($params['controller'])) {
             $params['controller'] = $this->params['controller'];
         }
         if (empty($params['action'])) {
             throw new Exception('Vous devez préciser l\'action vers laquelle vous redirigez la page');
         }
         $url = _url($params);
         if (is_null($url)) {
             throw new Exception('Impossible de trouver une url correspondante aux paramètres');
         }
         // Url
     } else {
         if (is_string($params)) {
             $url = Url::_($params);
         }
     }
     $this->response->redirect($url, $options);
 }