From a6a95e0027ea6252a5f67a91f4ecb9e3472102a6 Mon Sep 17 00:00:00 2001 From: absurdo Date: Wed, 25 Oct 2023 15:24:09 +0200 Subject: [PATCH] Added clasess support for routes --- libraries/Routes.php | 25 ++++++++++++++++++- modules/welcome/controllers/index.php | 35 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 modules/welcome/controllers/index.php diff --git a/libraries/Routes.php b/libraries/Routes.php index 49e8390..d59b1d0 100644 --- a/libraries/Routes.php +++ b/libraries/Routes.php @@ -13,13 +13,30 @@ class Config { } +/*Examples +* Url: http://domain.com/ +* Url: http://domain.com/index.php/{module} +* Url: http://domain.com/index.php/{module}/app/{arg1}/{arg2} -> modules/module/controller_app.php controller($args); +*/ + function get_controller($controller, $args=[]) { if(is_file($controller)) { include_once($controller); - return call_user_func_array('controller', $args); + if(class_exists('AppController')) { + + $controller=new \AppController(); + + //return $controller->App($args); + return call_user_func_array(array($controller, 'App'), $args); + + } + else { + + return call_user_func_array('controller', $args); + } } else { @@ -181,4 +198,10 @@ class Url { } +} + +class Controller { + + + } diff --git a/modules/welcome/controllers/index.php b/modules/welcome/controllers/index.php new file mode 100644 index 0000000..fb24b27 --- /dev/null +++ b/modules/welcome/controllers/index.php @@ -0,0 +1,35 @@ + 'Cool']; + + header('Content-Type: application/json; charset=utf-8'); + + return json_encode($data); + + break; + + } + + } + +}