Added clasess support for routes
This commit is contained in:
parent
1ef52579a3
commit
a6a95e0027
2 changed files with 59 additions and 1 deletions
|
|
@ -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=[]) {
|
function get_controller($controller, $args=[]) {
|
||||||
|
|
||||||
if(is_file($controller)) {
|
if(is_file($controller)) {
|
||||||
|
|
||||||
include_once($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 {
|
else {
|
||||||
|
|
@ -181,4 +198,10 @@ class Url {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
modules/welcome/controllers/index.php
Normal file
35
modules/welcome/controllers/index.php
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class AppController {
|
||||||
|
|
||||||
|
public function App($switch) {
|
||||||
|
|
||||||
|
switch($switch) {
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
return 'Welcome to the real world in class App!';
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'good':
|
||||||
|
|
||||||
|
return 'All things are good in class App!';
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'json':
|
||||||
|
|
||||||
|
$data=['data' => 'Cool'];
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
return json_encode($data);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue