/** * Método responsável por obter o nome do controlador e do método e executá-los. * @access public * @return void */ public static function run() { ob_start(); //pega o controller na URL Request::run(); Session::start(); $controller = Request::getCompleteController(); //verifica se o controlador existe if (file_exists(PATH_CONTROLLER . $controller . '.php')) { //instancia o controlador $controlador = NAMESPACE_CONTROLLER . "\\" . $controller; $controlador = new $controlador(); //pega o metodo da URL $action = Request::getAction(); //Transforma o resto da URL em Array $args = (array) Request::getArgs(); //verifica se o metodo existe no controlador $post = self::VerificaMetodo($controlador, $action); } else { Request::InverseArea(); $area = Request::getArea(); $controller = Request::getCompleteController(); if (file_exists(PATH_AREA . $area . DS . 'Controllers' . DS . $controller . '.php')) { //instancia o controlador $controlador = NAMESPACE_AREAS . "\\" . $area . "\\Controllers\\" . $controller; $controlador = new $controlador(); //pega o metodo da URL $action = Request::getAction(); //Transforma o resto da URL em Array $args = (array) Request::getArgs(); $post = self::VerificaMetodo($controlador, $action); } else { if (file_exists(PATH_CONTROLLER . CONTROLLER_404 . '.php')) { Request::setController(CONTROLLER_404); Request::setAction(ACTION_404); Request::setArea(null); $controlador = NAMESPACE_CONTROLLER . '\\' . CONTROLLER_404; $controlador = new $controlador(); $action = ACTION_404; //Transforma o resto da URL em Array $args = (array) Request::getArgs(); $post = self::VerificaMetodo($controlador, $action); } } } self::getPost($args); // try { call_user_func_array(array($controlador, $action . $post), $args); // }catch (\Exception $e){ // echo $e->getMessage(); // } $content = ob_get_clean(); Layout::render($content); }
static function getUrl($action, $controller = null, $area = null) { if ($controller == null) { $controller = Request::getController(); } if ($area == null && $controller != CONTROLLER_404) { $area = Request::getArea(); } $url = URL; if ($area != null) { $url .= $area . "/"; } $url .= (ucfirst($controller) == ucfirst(DEFAULT_CONTROLLER_ABV) && ucfirst($action) == ucfirst(DEFAULT_VIEW) ? "" : ucfirst($controller) . "/") . (ucfirst($action) == ucfirst(DEFAULT_VIEW) ? "" : ucfirst($action)); return $url; }
/** * @return string */ private function getClassModel() { //fora das areas if (Request::getArea() == null) { return $model = NAMESPACE_MODELS . '\\' . Request::getController(); } //dentro das areas return NAMESPACE_AREAS . '\\' . Request::getArea() . '\\' . 'Models' . '\\' . Request::getController(); }