Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Router {
- public $url_array;
- public $arguments;
- public function __construct(){
- $this->url_array = parse_url($_SERVER['REQUEST_URI'])['path'];
- $this->arguments = array_filter(explode("/", $this->url_array));
- $this->includeNecessaryFile();
- }
- public function includeNecessaryFile(){
- if(count($this->arguments) > 0){
- if(file_exists("main/".$this->arguments[1].".php") && $this->arguments[1] !== 'index'){
- require("main/".$this->arguments[1].".php");
- // any excess arguments are stored in Router.arguments and can be accessed by the included file using $this
- }
- } else {
- require("main/index.php");
- }
- }
- }
- $index_router = new Router();
Advertisement
Add Comment
Please, Sign In to add comment