Guest User

Untitled

a guest
Jun 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. class Router {
  4.    
  5.     private $controller, $action, $event;
  6.     private $rewrite;
  7.    
  8.     public function __construct() {
  9.         $this->init();
  10.     }
  11.    
  12.     public function getController(){
  13.     return $this->controller;
  14.     }
  15.    
  16.     public function getAction(){
  17.     return $this->action;
  18.     }
  19.    
  20.     public function getEvent(){
  21.     return $this->event;
  22.     }
  23.    
  24.     protected function init(){
  25.         //TODO PREG MATCH
  26.         $this->controller = isset($_GET['controller']) ? $_GET['controller'] : 'Misc';
  27.         $this->action = isset($_GET['action']) ? $_GET['action'] : 'Home';
  28.         if(isset($_GET['event']))$this->event = $_GET['event'];
  29.     }
  30.    
  31.     public function dispatch(){
  32.         $with_event = is_null($this->event);
  33.         $path = 'actions/'.$this->controller.'/'.$this->action;
  34.         if(!$with_event){$path .= '_'.$this->event;}
  35.         $path .= '.php';
  36.         if(!file_exists($path)){$path = 'actions/404.php';}
  37.         return require_once $path;
  38.     }
  39. }
  40.  
  41. ?>
Add Comment
Please, Sign In to add comment