+upd routes.json + router.page to have uri arguments (or any data separated by slashes in the array $_GET['uri'])

This commit is contained in:
xdrm-brackets 2018-02-20 17:17:53 +01:00
parent c8871cbab4
commit 7484bea239
2 changed files with 20 additions and 6 deletions

View File

@ -15,6 +15,7 @@
*/ */
public function __construct($url){ public function __construct($url){
$this->pagename = $url['page']; $this->pagename = $url['page'];
$this->uri = $url['uri'];
} }
@ -22,10 +23,22 @@
* *
*/ */
public function load(){ public function load(){
if( file_exists(__PUBLIC__."/page/".$this->pagename.".php") )
include __PUBLIC__."/page/".$this->pagename.".php"; /* (1) Build page file name */
else $page_fname = __PUBLIC__."/page/".$this->pagename.".php";
echo "page not found";
/* (2) If page does not exist -> 404 */
if( !file_exists($page_fname) ){
http_response_code(404);
die('Page not found');
}
/* (3) Set URI arguments */
$_GET['uri'] = explode('/', $this->uri);
/* (4) Load page */
include __PUBLIC__."/page/".$this->pagename.".php";
} }
/* POST-CALL /* POST-CALL

View File

@ -20,11 +20,12 @@
} }
}, },
"/{page}/": { "/{page}/{uri}": {
"methods": ["GET"], "methods": ["GET"],
"controller": "page:load", "controller": "page:load",
"arguments": { "arguments": {
"page": "[a-z]+" "page": "[a-z]+",
"uri": ".*"
} }
}, },