Beispiel #1
0
#composer
if (file_exists(implode(DS, [BASEPATH, 'vendor', 'autoload.php']))) {
    include implode(DS, [BASEPATH, 'vendor', 'autoload.php']);
}
#routing
$routing = new Routing(PATH_INFO);
$class = $routing->get_action();
$method = $routing->get_method();
$parameters = $routing->get_parameters();
// var_dump($routing->get_action(), $routing->get_method(), $routing->get_parameters());
#run the current controller
$controller_path = implode(DS, [BASEPATH, 'controller', "{$class}.php"]);
#if controller not exist, use the default action & default method
if (!file_exists($controller_path)) {
    # set routing action & method to default
    $routing->set_action_used_default();
    $routing->set_method_used_default();
    $class = Routing::DEFAULT_ACTION;
    $controller_path = implode(DS, [BASEPATH, 'controller', "{$class}.php"]);
    $method = $routing->get_method();
    #method already set to default
}
#load the controller file
require_once $controller_path;
#instatiate controller object
$controller_object = new $class($routing);
#check, if method is not exist, then use the default method
if (!method_exists($controller_object, $method)) {
    # set routing method to default
    $routing->set_method_used_default();
    $method = $routing->get_method();