From 7484bea239f6d275b0e71e520eb27ef0605bd0fd Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 20 Feb 2018 17:17:53 +0100 Subject: [PATCH] +upd routes.json + router.page to have uri arguments (or any data separated by slashes in the array $_GET['uri']) --- build/router/controller/page.php | 21 +++++++++++++++++---- config/routes.json | 5 +++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/build/router/controller/page.php b/build/router/controller/page.php index 867c427..18a92a1 100644 --- a/build/router/controller/page.php +++ b/build/router/controller/page.php @@ -15,6 +15,7 @@ */ public function __construct($url){ $this->pagename = $url['page']; + $this->uri = $url['uri']; } @@ -22,10 +23,22 @@ * */ public function load(){ - if( file_exists(__PUBLIC__."/page/".$this->pagename.".php") ) - include __PUBLIC__."/page/".$this->pagename.".php"; - else - echo "page not found"; + + /* (1) Build page file name */ + $page_fname = __PUBLIC__."/page/".$this->pagename.".php"; + + /* (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 diff --git a/config/routes.json b/config/routes.json index d92fda3..8658fbc 100644 --- a/config/routes.json +++ b/config/routes.json @@ -20,11 +20,12 @@ } }, - "/{page}/": { + "/{page}/{uri}": { "methods": ["GET"], "controller": "page:load", "arguments": { - "page": "[a-z]+" + "page": "[a-z]+", + "uri": ".*" } },