Controller weiter vereinfacht:
authorMarkus Bröker <broeker.markus@googlemail.com>
Fri, 13 Nov 2015 23:08:19 +0100
changeset 22 16ebd5c503fe
parent 21 4d61a248fd41
child 23 975b2839f1f3
Controller weiter vereinfacht: => Unnötige Abhängigkeit vom Controller entfernt
classes/bfw/core/Controller.php
classes/bfw/mvc/controller/BenutzerverwaltungController.php
classes/bfw/mvc/controller/DokumentationController.php
classes/bfw/mvc/controller/ErrorController.php
classes/bfw/mvc/controller/HomeController.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
--- 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();
     }
 
     /**
--- 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
--- 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();
     }
 
 }
--- 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