Commit initial
This commit is contained in:
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
require_once $GLOBALS['app_path'].'Framework/Request.php';
|
||||
require_once $GLOBALS['app_path'].'Framework/View.php';
|
||||
|
||||
abstract class Controller {
|
||||
|
||||
private $action;
|
||||
|
||||
protected $request;
|
||||
|
||||
public function setRequest(Request $request) {
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function executeAction($action) {
|
||||
if (method_exists($this, $action)) {
|
||||
$this->action = $action;
|
||||
$this->{$this->action}();
|
||||
}
|
||||
else {
|
||||
$classController = get_class($this);
|
||||
throw new Exception("Action '$action' non définie dans la classe $classController");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract function index();
|
||||
|
||||
protected function generateView($dataView = array(), $action = null) {
|
||||
|
||||
$actionView = $this->action;
|
||||
if ($action != null)
|
||||
$actionView = $action;
|
||||
|
||||
$classController = get_class($this);
|
||||
$controller = str_replace("Controller", "", $classController);
|
||||
$vue = new View($actionView, $controller);
|
||||
$vue->generate($dataView);
|
||||
}
|
||||
|
||||
protected function redirect($controller, $action = null)
|
||||
{
|
||||
$root = Configuration::get("root", "/");
|
||||
header("Location:" . $root . $controller . "/" . $action);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user