Controller weiter vereinfacht:
=> Unnötige Abhängigkeit vom Controller entfernt
--- 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