Skip to content

Commit f44e31c

Browse files
committed
extract GET data,named routes function
1 parent efd394f commit f44e31c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

index.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
session_start();
33
require_once "lib/sql.php";
44
require_once "lib/helper.php";
5-
api();
5+
6+
route("/","api/items");
67
?>

lib/helper.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ function strposX($haystack, $needle, $number = 0)
1717
);
1818
}
1919

20-
function api(){
20+
function api($api=null){
2121
global $path;
22+
if($api!=null) $path = $api;
2223
if(isset($_POST)) extract($_POST);
24+
if(isset($_GET)) extract($_GET);
2325
if(!file_exists("api/$path.php")){
2426
if(!file_exists("api/$path/index.php")){
2527
header("HTTP/1.1 404 Not Found");
@@ -34,4 +36,12 @@ function api(){
3436
include "api/$path.php";
3537
}
3638

39+
function route($routeName,$api){
40+
global $path;
41+
if($routeName==$path){
42+
api($api);
43+
exit();
44+
}
45+
}
46+
3747

0 commit comments

Comments
 (0)