Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Router {
- private $controller, $action, $event;
- private $rewrite;
- public function __construct() {
- $this->init();
- }
- public function getController(){
- return $this->controller;
- }
- public function getAction(){
- return $this->action;
- }
- public function getEvent(){
- return $this->event;
- }
- protected function init(){
- //TODO PREG MATCH
- $this->controller = isset($_GET['controller']) ? $_GET['controller'] : 'Misc';
- $this->action = isset($_GET['action']) ? $_GET['action'] : 'Home';
- if(isset($_GET['event']))$this->event = $_GET['event'];
- }
- public function dispatch(){
- $with_event = is_null($this->event);
- $path = 'actions/'.$this->controller.'/'.$this->action;
- if(!$with_event){$path .= '_'.$this->event;}
- $path .= '.php';
- if(!file_exists($path)){$path = 'actions/404.php';}
- return require_once $path;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment