Skip to content

Commit 1ca6e53

Browse files
committed
fix(send params via path):
fixed #5
1 parent 59d2ec9 commit 1ca6e53

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

app/Config/Bootstrap.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ public static function run()
99
if(!empty($target)) {
1010
$controller = $target['controller'];
1111
$method = $target['method'];
12+
$params = $target['params'];
1213
if(class_exists('\app\Controllers\\'.$controller.'Controller')) {
1314
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);
1516
} else {
1617
echo 'Page Not Found 404 : Method Not Found in Controller '.$controller;
1718
}
@@ -28,10 +29,18 @@ private static function getPath()
2829
{
2930
// php.net/manual/en/function.explode.php (split in js)
3031
$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+
3240
return [
3341
'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
3544
];
3645
}
3746

app/Controllers/DirectoriesController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ public function index(){
1414
return View::display('DirectoryList', $data);
1515
}
1616

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>';
1923
}
2024

2125
}

0 commit comments

Comments
 (0)