# HG changeset patch # User Markus Bröker # Date 1447452499 -3600 # Node ID 16ebd5c503fea57e005fe805d72d8690682953d8 # Parent 4d61a248fd41cc339e3417fd6660f51954e0ca8f Controller weiter vereinfacht: => Unnötige Abhängigkeit vom Controller entfernt diff --git a/classes/bfw/core/Controller.php b/classes/bfw/core/Controller.php --- a/classes/bfw/core/Controller.php +++ b/classes/bfw/core/Controller.php @@ -36,18 +36,30 @@ /** * Controller constructor. * - * @param Model $model */ - public function __construct(Model $model) { + public function __construct() { $this->request = new Request(); $this->response = new Response(); - $this->model = $model; - $this->view = new View($this, $model); + $this->model = $this->getDataModelInstance(); + $this->view = new View($this, $this->model); $this->logger = Logger::getLogger(get_class($this)); } + public function getDataModelInstance() { + $modelName = $this->getModelName(); + + return new $modelName(); + } + + private function getModelName() { + $modelName = str_replace('controller', 'model', get_class($this)); + $modelName = strtolower($modelName); + + return str_replace('controller', '\DataModel', $modelName); + } + /** * @param $controller * @return string @@ -118,17 +130,4 @@ * @return mixed */ abstract public function index(); - - public function getDataModelInstance() { - $modelName = $this->getModelName(); - - return new $modelName(); - } - - private function getModelName() { - $modelName = str_replace('controller', 'model', get_class($this)); - $modelName = strtolower($modelName); - - return str_replace('controller', '\DataModel', $modelName); - } } \ No newline at end of file diff --git a/classes/bfw/mvc/controller/BenutzerverwaltungController.php b/classes/bfw/mvc/controller/BenutzerverwaltungController.php --- a/classes/bfw/mvc/controller/BenutzerverwaltungController.php +++ b/classes/bfw/mvc/controller/BenutzerverwaltungController.php @@ -18,8 +18,7 @@ * */ public function __construct() { - $model = $this->getDataModelInstance(); - parent::__construct($model); + parent::__construct(); } /** diff --git a/classes/bfw/mvc/controller/DokumentationController.php b/classes/bfw/mvc/controller/DokumentationController.php --- a/classes/bfw/mvc/controller/DokumentationController.php +++ b/classes/bfw/mvc/controller/DokumentationController.php @@ -17,11 +17,12 @@ class DokumentationController extends Controller { public function __construct() { - $model = $this->getDataModelInstance(); - parent::__construct($model); + parent::__construct(); } public function index() { - + $request = $this->getRequest(); + $view = $this->getView(); + $model = $this->getModel(); } } \ No newline at end of file diff --git a/classes/bfw/mvc/controller/ErrorController.php b/classes/bfw/mvc/controller/ErrorController.php --- a/classes/bfw/mvc/controller/ErrorController.php +++ b/classes/bfw/mvc/controller/ErrorController.php @@ -16,13 +16,13 @@ class ErrorController extends Controller { public function __construct() { - $model = $this->getDataModelInstance(); - parent::__construct($model); + parent::__construct(); } public function index() { $request = $this->getRequest(); - $engine = $this->getView(); + $view = $this->getView(); + $model = $this->getModel(); } } diff --git a/classes/bfw/mvc/controller/HomeController.php b/classes/bfw/mvc/controller/HomeController.php --- a/classes/bfw/mvc/controller/HomeController.php +++ b/classes/bfw/mvc/controller/HomeController.php @@ -15,20 +15,17 @@ * */ public function __construct() { - $model = $this->getDataModelInstance(); - parent::__construct($model); + parent::__construct(); } /** * Default Index Action * - * Zu berücksichtigen ist hier: - * - * Sowohl GET-Actions als auch POST Actions werden berücksichtigt */ public function index() { $request = $this->getRequest(); - $engine = $this->getView(); + $view = $this->getView(); + $model = $this->getModel(); } } \ No newline at end of file