예제 #1
0
 /**
  * The method finds in the controller directory and runs action, selected
  * in accordance with the incoming parameter.
  * @param type $action
  * @return string
  * @throws Exception
  * @version 14.11.2014
  */
 public static function run($action = "index")
 {
     if (empty($action)) {
         $action = "index";
     }
     // Determine, whether the controller is selected.
     if (empty(self::$controller)) {
         throw new Exception(_("Controller parameter is not set."));
     }
     // For security purposes, we will add additional validation
     // on user input.
     if (!preg_match("/[-_0-9a-z]{2,15}/u", $action)) {
         throw new Exception(_("Controller Action parameter is not valid."));
     }
     self::$action = $action;
     // Define path to the actions of selected controller.
     $SubControllerPath = MODULE_PATH . "controller-" . self::$controller . "/";
     // If Action file is not found - return false. Else - include it.
     if (!is_file($SubControllerPath . $action . ".php")) {
         throw new Exception(_("Controller Action is not found."));
     }
     require_once $SubControllerPath . $action . ".php";
     // Define Contoller Action function name and run it.
     $ActFunction = "controller_" . self::$controller . "_" . $action;
     if (!function_exists($ActFunction)) {
         throw new Exception(_("Controller Action is not found."));
     }
     return $ActFunction();
 }
예제 #2
0
<?php

include_once 'controller/controller.php';
$model = new model();
$view = new view();
$controller = new controller($model, $view);
echo $controller->action();