1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,75 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-class Url |
|
4 |
-{ |
|
5 |
- public $page; |
|
6 |
- |
|
7 |
- |
|
8 |
- public function __construct(){ |
|
9 |
- |
|
10 |
- $page = array(); |
|
11 |
- $page['name'] = 'accueil'; |
|
12 |
- $page['description'] = ""; |
|
13 |
- $page['params'] = array(); |
|
14 |
- $page['control'] = false; |
|
15 |
- |
|
16 |
- |
|
17 |
- |
|
18 |
- $url = parse_url($_SERVER['REQUEST_URI']); |
|
19 |
- $urlTrim = trim( $url['path'] , '/' ); |
|
20 |
- $urlParts = explode('/' , $urlTrim ); |
|
21 |
- |
|
22 |
- array_shift($urlParts); |
|
23 |
- array_shift($urlParts); |
|
24 |
- |
|
25 |
- //print_r($urlParts); |
|
26 |
- //Récupération du nom de la page |
|
27 |
- ($urlParts[0] == 'index' || $urlParts[0] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[0]; |
|
28 |
- //array_shift($urlParts); |
|
29 |
- unset($urlParts[0]); |
|
30 |
- |
|
31 |
- if($page['name'] == 'control'){ |
|
32 |
- $page['control'] = true; |
|
33 |
- ($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1]; |
|
34 |
- //array_shift($urlParts); |
|
35 |
- unset($urlParts[1]); |
|
36 |
- |
|
37 |
- } |
|
38 |
- |
|
39 |
- //vérification du nombre de parametres: s'il n'existe pas autant de clé que |
|
40 |
- // de valeurs on sort de la fonction et on renvoie une page d'erreur. |
|
41 |
- $numParts = count($urlParts); |
|
42 |
- if ( $numParts%2 != 0 ) { |
|
43 |
- $page['name'] = 'error'; |
|
44 |
- $page['params'] = array(); |
|
45 |
- return $page; |
|
46 |
- }else if ( $numParts != 0 ){ |
|
47 |
- $values = array(); |
|
48 |
- $keys = array(); |
|
49 |
- foreach( $urlParts as $key => $value ){ |
|
50 |
- if($key%2 == 0) { |
|
51 |
- $values[] = $value; |
|
52 |
- } else { |
|
53 |
- $keys[] = $value; |
|
54 |
- } |
|
55 |
- } |
|
56 |
- if($page['control']){ |
|
57 |
- $page['params'] = array_combine($values, $keys); |
|
58 |
- }else { |
|
59 |
- $page['params'] = array_combine($keys, $values); |
|
60 |
- } |
|
61 |
- } |
|
62 |
- |
|
63 |
- //verification de l'existence de la page dans les controlleurs |
|
64 |
- if($page['control']){ |
|
65 |
- $pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
66 |
- }else { |
|
67 |
- $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
68 |
- } |
|
69 |
- |
|
70 |
- if(!file_exists($pageFile)){ |
|
71 |
- $page['name'] = 'error'; |
|
72 |
- } |
|
73 |
- $this->page = $page; |
|
74 |
- } |
|
75 |
-} |
... | ... |
@@ -11,14 +11,30 @@ class Url |
11 | 11 |
$page['name'] = 'accueil'; |
12 | 12 |
$page['description'] = ""; |
13 | 13 |
$page['params'] = array(); |
14 |
- |
|
14 |
+ $page['control'] = false; |
|
15 |
+ |
|
16 |
+ |
|
17 |
+ |
|
15 | 18 |
$url = parse_url($_SERVER['REQUEST_URI']); |
16 | 19 |
$urlTrim = trim( $url['path'] , '/' ); |
17 | 20 |
$urlParts = explode('/' , $urlTrim ); |
18 |
- |
|
21 |
+ |
|
22 |
+ array_shift($urlParts); |
|
23 |
+ array_shift($urlParts); |
|
24 |
+ |
|
25 |
+ //print_r($urlParts); |
|
19 | 26 |
//Récupération du nom de la page |
20 | 27 |
($urlParts[0] == 'index' || $urlParts[0] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[0]; |
21 |
- unset($urlParts[0]); |
|
28 |
+ //array_shift($urlParts); |
|
29 |
+ unset($urlParts[0]); |
|
30 |
+ |
|
31 |
+ if($page['name'] == 'control'){ |
|
32 |
+ $page['control'] = true; |
|
33 |
+ ($urlParts[1] == 'index' || $urlParts[1] == '' ) ? $page['name']='accueil' : $page['name']=$urlParts[1]; |
|
34 |
+ //array_shift($urlParts); |
|
35 |
+ unset($urlParts[1]); |
|
36 |
+ |
|
37 |
+ } |
|
22 | 38 |
|
23 | 39 |
//vérification du nombre de parametres: s'il n'existe pas autant de clé que |
24 | 40 |
// de valeurs on sort de la fonction et on renvoie une page d'erreur. |
... | ... |
@@ -37,17 +53,23 @@ class Url |
37 | 53 |
$keys[] = $value; |
38 | 54 |
} |
39 | 55 |
} |
40 |
- $page['params'] = array_combine($keys, $values); |
|
56 |
+ if($page['control']){ |
|
57 |
+ $page['params'] = array_combine($values, $keys); |
|
58 |
+ }else { |
|
59 |
+ $page['params'] = array_combine($keys, $values); |
|
60 |
+ } |
|
41 | 61 |
} |
42 | 62 |
|
43 | 63 |
//verification de l'existence de la page dans les controlleurs |
44 |
- |
|
45 |
- $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
64 |
+ if($page['control']){ |
|
65 |
+ $pageFile = TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
66 |
+ }else { |
|
67 |
+ $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
68 |
+ } |
|
46 | 69 |
|
47 | 70 |
if(!file_exists($pageFile)){ |
48 | 71 |
$page['name'] = 'error'; |
49 | 72 |
} |
50 | 73 |
$this->page = $page; |
51 |
- |
|
52 | 74 |
} |
53 | 75 |
} |
... | ... |
@@ -6,7 +6,7 @@ class Url |
6 | 6 |
|
7 | 7 |
|
8 | 8 |
public function __construct(){ |
9 |
- |
|
9 |
+ |
|
10 | 10 |
$page = array(); |
11 | 11 |
$page['name'] = 'accueil'; |
12 | 12 |
$page['description'] = ""; |
... | ... |
@@ -41,15 +41,13 @@ class Url |
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
//verification de l'existence de la page dans les controlleurs |
44 |
- |
|
44 |
+ |
|
45 | 45 |
$pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
46 | 46 |
|
47 | 47 |
if(!file_exists($pageFile)){ |
48 | 48 |
$page['name'] = 'error'; |
49 | 49 |
} |
50 |
- |
|
51 | 50 |
$this->page = $page; |
52 |
- |
|
53 |
- |
|
51 |
+ |
|
54 | 52 |
} |
55 | 53 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,55 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+class Url |
|
4 |
+{ |
|
5 |
+ public $page; |
|
6 |
+ |
|
7 |
+ |
|
8 |
+ public function __construct(){ |
|
9 |
+ |
|
10 |
+ $page = array(); |
|
11 |
+ $page['name'] = 'accueil'; |
|
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']='accueil' : $page['name']=$urlParts[0]; |
|
21 |
+ unset($urlParts[0]); |
|
22 |
+ |
|
23 |
+ //vérification du nombre de parametres: s'il n'existe pas autant de clé que |
|
24 |
+ // de valeurs on sort de la fonction et on renvoie une page d'erreur. |
|
25 |
+ $numParts = count($urlParts); |
|
26 |
+ if ( $numParts%2 != 0 ) { |
|
27 |
+ $page['name'] = 'error'; |
|
28 |
+ $page['params'] = array(); |
|
29 |
+ return $page; |
|
30 |
+ }else if ( $numParts != 0 ){ |
|
31 |
+ $values = array(); |
|
32 |
+ $keys = array(); |
|
33 |
+ foreach( $urlParts as $key => $value ){ |
|
34 |
+ if($key%2 == 0) { |
|
35 |
+ $values[] = $value; |
|
36 |
+ } else { |
|
37 |
+ $keys[] = $value; |
|
38 |
+ } |
|
39 |
+ } |
|
40 |
+ $page['params'] = array_combine($keys, $values); |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ //verification de l'existence de la page dans les controlleurs |
|
44 |
+ |
|
45 |
+ $pageFile = CONTROLLERS_PATH . DIRECTORY_SEPARATOR . $page['name'] . '.php'; |
|
46 |
+ |
|
47 |
+ if(!file_exists($pageFile)){ |
|
48 |
+ $page['name'] = 'error'; |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ $this->page = $page; |
|
52 |
+ |
|
53 |
+ |
|
54 |
+ } |
|
55 |
+} |