1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,56 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-class Url |
|
4 |
-{ |
|
5 |
- public $page; |
|
6 |
- |
|
7 |
- |
|
8 |
- public function __contstruct(){ |
|
9 |
- |
|
10 |
- $page = array(); |
|
11 |
- $page['name'] = '1'; |
|
12 |
- $page['description'] = ""; |
|
13 |
- $page['params'] = array(); |
|
14 |
- |
|
15 |
- $url = parse_url($_SERVER['REQUEST_URI']); |
|
16 |
- $urlTrim = trim( $url['path'] , '/' ); |
|
17 |
- $urlParts = explode('/' , $urlTrim ); |
|
18 |
- |
|
19 |
- //Récupération du nom de la page |
|
20 |
- ($urlParts[0] == 'index' ||$urlParts[0] == '' )?$page['name']='home':$page['name']=$urlParts[0]; |
|
21 |
- |
|
22 |
- unset($urlParts[0]); |
|
23 |
- |
|
24 |
- //vérification du nombre de parametres: s'il n'existe pas autant de clé que |
|
25 |
- // de valeurs on sort de la fonction et on renvoie une page d'erreur. |
|
26 |
- $numParts = count($urlParts); |
|
27 |
- if ( $numParts%2 != 0 ) { |
|
28 |
- $page['name'] = 'error'; |
|
29 |
- $page['params'] = array(); |
|
30 |
- return $page; |
|
31 |
- }else if ( $numParts != 0 ){ |
|
32 |
- $values = array(); |
|
33 |
- $keys = array(); |
|
34 |
- foreach( $urlParts as $key => $value ){ |
|
35 |
- if($key%2 == 0) { |
|
36 |
- $values[] = $value; |
|
37 |
- } else { |
|
38 |
- $keys[] = $value; |
|
39 |
- } |
|
40 |
- } |
|
41 |
- $page['params'] = array_combine($keys, $values); |
|
42 |
- } |
|
43 |
- |
|
44 |
- //verification de l'existence de la page dans les controlleurs |
|
45 |
- |
|
46 |
- $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
47 |
- |
|
48 |
- if(!file_exists($pageFile)){ |
|
49 |
- $page['name'] = 'error'; |
|
50 |
- } |
|
51 |
- |
|
52 |
- $this->$page = $page; |
|
53 |
- |
|
54 |
- |
|
55 |
- } |
|
56 |
-} |
Dear IP-formation.
Emmanuel ROY authored on 15/04/2015 14:45:541 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,56 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+class Url |
|
4 |
+{ |
|
5 |
+ public $page; |
|
6 |
+ |
|
7 |
+ |
|
8 |
+ public function __contstruct(){ |
|
9 |
+ |
|
10 |
+ $page = array(); |
|
11 |
+ $page['name'] = '1'; |
|
12 |
+ $page['description'] = ""; |
|
13 |
+ $page['params'] = array(); |
|
14 |
+ |
|
15 |
+ $url = parse_url($_SERVER['REQUEST_URI']); |
|
16 |
+ $urlTrim = trim( $url['path'] , '/' ); |
|
17 |
+ $urlParts = explode('/' , $urlTrim ); |
|
18 |
+ |
|
19 |
+ //Récupération du nom de la page |
|
20 |
+ ($urlParts[0] == 'index' ||$urlParts[0] == '' )?$page['name']='home':$page['name']=$urlParts[0]; |
|
21 |
+ |
|
22 |
+ unset($urlParts[0]); |
|
23 |
+ |
|
24 |
+ //vérification du nombre de parametres: s'il n'existe pas autant de clé que |
|
25 |
+ // de valeurs on sort de la fonction et on renvoie une page d'erreur. |
|
26 |
+ $numParts = count($urlParts); |
|
27 |
+ if ( $numParts%2 != 0 ) { |
|
28 |
+ $page['name'] = 'error'; |
|
29 |
+ $page['params'] = array(); |
|
30 |
+ return $page; |
|
31 |
+ }else if ( $numParts != 0 ){ |
|
32 |
+ $values = array(); |
|
33 |
+ $keys = array(); |
|
34 |
+ foreach( $urlParts as $key => $value ){ |
|
35 |
+ if($key%2 == 0) { |
|
36 |
+ $values[] = $value; |
|
37 |
+ } else { |
|
38 |
+ $keys[] = $value; |
|
39 |
+ } |
|
40 |
+ } |
|
41 |
+ $page['params'] = array_combine($keys, $values); |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ //verification de l'existence de la page dans les controlleurs |
|
45 |
+ |
|
46 |
+ $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
47 |
+ |
|
48 |
+ if(!file_exists($pageFile)){ |
|
49 |
+ $page['name'] = 'error'; |
|
50 |
+ } |
|
51 |
+ |
|
52 |
+ $this->$page = $page; |
|
53 |
+ |
|
54 |
+ |
|
55 |
+ } |
|
56 |
+} |