Пример #1
0
 /**
  * Execute controller's specified action
  */
 public function execute()
 {
     // Get action
     $action = StringTools::noPathFilterInput(INPUT_GET, 'action');
     if (empty($action) || !method_exists($this, $action)) {
         if (method_exists($this, 'index')) {
             $action = 'index';
         } else {
             return;
         }
     }
     $this->_action = $action;
     // Call the action's method
     $this->{$action}();
 }
Пример #2
0
 * @author Jeremy Lacoude
 */
// Configure autoload
// Modify include path to add class and interfaces dir. Can be removed if added in php.ini
set_include_path(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'interfaces' . DIRECTORY_SEPARATOR . PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR);
spl_autoload_extensions('.php');
spl_autoload_register('loadClass');
// Send headers
header("Content-type: text/html; charset=UTF-8");
// Register error and exception handlers
set_exception_handler(array('Debug', 'exceptionHandler'));
set_error_handler(array('Debug', 'errorHandler'));
// Load dependency container
$DI = new DependencyInjectionContainer(__DIR__ . '/../config/app.ini');
// Manage page parameters to load the desired controller
$controller = StringTools::noPathFilterInput(INPUT_GET, 'controller');
if (!empty($controller)) {
    $controller = $controller;
} else {
    $controller = 'Main';
}
$ctrl = new $controller($DI);
$ctrl->execute();
$ctrl->loadTemplate();
/**
 * Function used to load a file where a class is defined
 * @param string $className Name of the class
 */
function loadClass($className)
{
    $paths = explode(PATH_SEPARATOR, get_include_path());