public function start() { $controller_path = "application/controllers/" . $this->controller . '.php'; if (file_exists($controller_path)) { include "application/controllers/" . $this->controller . '.php'; } else { Router::ErrorPage404(); } $controller = new $this->controller(); $action = $this->action; if (method_exists($controller, $action)) { $controller->{$action}(); } else { Router::ErrorPage404(); } }
static function start() { // default controller $controller_name = 'Main'; $action_name = 'index'; $routes = explode('/', $_SERVER['REQUEST_URI']); // get controller name if (!empty($routes[1])) { $controller_name = $routes[1]; } // get method name if (!empty($routes[2])) { $action_name = $routes[2]; } // add prefix $model_name = 'Model_' . $controller_name; $controller_name = 'Controller_' . $controller_name; $action_name = 'action_' . $action_name; // get file with model class $model_file = strtolower($model_name) . '.php'; $model_path = "application/models/" . $model_file; if (file_exists($model_path)) { include "application/models/" . $model_file; } // get file with controller $controller_file = strtolower($controller_name) . '.php'; $controller_path = "application/controllers/" . $controller_file; if (file_exists($controller_path)) { include "application/controllers/" . $controller_file; } else { Router::ErrorPage404(); } // crete controller $controller = new $controller_name(); $action = $action_name; if (method_exists($controller, $action)) { // get controller action $controller->{$action}(); } else { // here we can throw exception , but now just redirect Router::ErrorPage404(); } }