public function route($url) { // Split the URL into parts $url_array = array(); $url_array = explode("/", $url); // The first part of the URL is the controller name $controller = isset($url_array[0]) ? $url_array[0] : ''; array_shift($url_array); // The second part is the method name $action = isset($url_array[1]) ? $url_array[1] : ''; array_shift($url_array); // The third part are the parameters $query_string = $url_array; // if controller is empty, redirect to default controller if (empty($controller)) { $controller = default_controller(); } // if action is empty, redirect to index page if (empty($action)) { $action = 'index'; } $controller_name = $controller; $controller = ucwords($controller); $dispatch = new $controller($controller_name, $action); if ((int) method_exists($controller, $action)) { call_user_func_array(array($dispatch, $action), $query_string); } else { /* Error Generation Code Here */ } }
public function Init() { /** * show all errors */ show_errors(); /** * check if page is secured */ if (protocol() == 'https') { forceHTTPS(); } /** * initializing session */ sessions::init(); /** * getting requested url */ $this->Get_Url(); /** * replace - to _ */ array_walk($this->_Url, array($this, 'Url_replace')); /** * check if controller name not exists */ if (empty($this->_Url[0])) { $this->_Url[0] = default_controller(); } $this->Set_Controller(); $this->Set_Method(); }