Vous êtes connecté en tant que anonymous Se Deconnecter
application/class/url.class.php
137b5e76
 <?php
 
 class Url
 {
 	public $page;
 	
 	
aed8ee26
 	public function __construct(){
ff461209
 
aed8ee26
 	$page = array();
 	$page['name'] = 'accueil';
 	$page['params'] = array();
3957c7ee
 	$page['control'] = false;
 
 
 
aed8ee26
 	$url = parse_url($_SERVER['REQUEST_URI']);
 	$urlTrim = trim( $url['path'] , '/' );
137b5e76
 	$urlParts = explode('/' , $urlTrim );
3957c7ee
 
 	array_shift($urlParts);
 	array_shift($urlParts);
 
 	//print_r($urlParts);
aed8ee26
 	//Récupération du nom de la page
74c94f79
         if(isset($urlParts[0])) {
             ($urlParts[0] == 'index' || $urlParts[0] == '') ? $page['name'] = 'accueil' : $page['name'] = $urlParts[0];
             //array_shift($urlParts);
             unset($urlParts[0]);
         }else{
             $page['name'] = 'accueil';
         }
3957c7ee
 
 	if($page['name'] == 'control'){
 	    $page['control'] = true;
         ($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1];
         //array_shift($urlParts);
         unset($urlParts[1]);
 
     }
aed8ee26
 
 	//vérification du nombre de parametres: s'il n'existe pas autant de clé que
 	// de valeurs on sort de la fonction et on renvoie une page d'erreur.
 	$numParts = count($urlParts);
 	if ( $numParts%2 != 0 ) {
 		$page['name'] = 'error';
 		$page['params'] = array();
 		return $page;
 	}else if ( $numParts != 0 ){
 		$values = array();
 		$keys = array();
 		foreach( $urlParts as $key => $value ){
 			if($key%2 == 0) {
 				$values[] = $value;
 			} else {
 				$keys[] = $value;
 			}
 		}
3957c7ee
 		if($page['control']){
             $page['params'] = array_combine($values, $keys);
         }else {
             $page['params'] = array_combine($keys, $values);
         }
aed8ee26
 	}
137b5e76
 	
 	//verification de l'existence de la page dans les controlleurs
3957c7ee
     if($page['control']){
         $pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php';
     }else {
         $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php';
 	}
aed8ee26
 	
 	if(!file_exists($pageFile)){
 		$page['name'] = 'error';
137b5e76
 	}
aed8ee26
 	$this->page = $page;
137b5e76
 	}
 }