working on v4
This commit is contained in:
		
							
								
								
									
										30
									
								
								v4/libraries/router.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								v4/libraries/router.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
<?php
 | 
			
		||||
class Router {
 | 
			
		||||
	public $returned = false;
 | 
			
		||||
 | 
			
		||||
	function route($url, $filename) {
 | 
			
		||||
		if($_SERVER['REQUEST_METHOD'] == 'GET') {
 | 
			
		||||
			if ($_SERVER['REQUEST_URI'] == $url) {
 | 
			
		||||
				require_once("./pages/$filename/$filename.php");
 | 
			
		||||
				$this->returned = true;
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function __destruct() {
 | 
			
		||||
		if($_SERVER['REQUEST_METHOD'] == 'GET') {
 | 
			
		||||
			if(!$this->returned){
 | 
			
		||||
				$url = explode("/", $_SERVER['REQUEST_URI']);
 | 
			
		||||
				$url = $url[count($url)-1];
 | 
			
		||||
 | 
			
		||||
				if (file_exists("./pages/$url/$url.php")) {
 | 
			
		||||
					require_once("./pages/$url/$url.php");
 | 
			
		||||
				} else {
 | 
			
		||||
					require_once("./pages/errors/404.php");
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user