File tree 2 files changed +18
-5
lines changed
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,10 @@ public static function run()
9
9
if (!empty ($ target )) {
10
10
$ controller = $ target ['controller ' ];
11
11
$ method = $ target ['method ' ];
12
+ $ params = $ target ['params ' ];
12
13
if (class_exists ('\app\Controllers \\' .$ controller .'Controller ' )) {
13
14
if (method_exists ('app\Controllers \\' .$ controller .'Controller ' , $ method )) {
14
- echo call_user_func (array ('\app\Controllers \\' .$ controller .'Controller ' , $ method ));
15
+ echo call_user_func (array ('\app\Controllers \\' .$ controller .'Controller ' , $ method ), $ params );
15
16
} else {
16
17
echo 'Page Not Found 404 : Method Not Found in Controller ' .$ controller ;
17
18
}
@@ -28,10 +29,18 @@ private static function getPath()
28
29
{
29
30
// php.net/manual/en/function.explode.php (split in js)
30
31
$ path = explode ('/ ' , $ _SERVER ['PATH_INFO ' ]);
31
- // print_r($_SERVER['PATH_INFO']);
32
+ $ params = [];
33
+ // save params to array
34
+ if (count ($ path ) > 3 ) {
35
+ for ($ n =3 ; $ n < count ($ path ) ; $ n ++) {
36
+ array_push ($ params , $ path [$ n ]);
37
+ }
38
+ }
39
+
32
40
return [
33
41
'controller ' => empty ($ path [1 ]) ? 'Home ' : ucfirst ($ path [1 ]),
34
- 'method ' => empty ($ path [2 ]) ? 'index ' : $ path [2 ]
42
+ 'method ' => empty ($ path [2 ]) ? 'index ' : $ path [2 ],
43
+ 'params ' => $ params
35
44
];
36
45
}
37
46
Original file line number Diff line number Diff line change @@ -14,8 +14,12 @@ public function index(){
14
14
return View::display ('DirectoryList ' , $ data );
15
15
}
16
16
17
- public function detail (){
18
- return '<h1>Directories Detail</h1> ' ;
17
+ /**
18
+ * access using sample path /directories/detail/12
19
+ * @param $params array
20
+ */
21
+ public function detail ($ params ){
22
+ return '<h1>Directories Detail of id : ' .$ params [0 ].'</h1> ' ;
19
23
}
20
24
21
25
}
You can’t perform that action at this time.
0 commit comments