Die View erzeugt das UI und nicht mehr der Dispatcher
authorMarkus Bröker <broeker.markus@googlemail.com>
Sat, 14 Nov 2015 02:42:53 +0100
changeset 25 7fddaf017915
parent 24 ef2914b7af78
child 26 77b1d5c1ccf1
Die View erzeugt das UI und nicht mehr der Dispatcher
classes/bfw/Dispatcher.php
classes/bfw/core/View.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
index.php
--- a/classes/bfw/Dispatcher.php
+++ b/classes/bfw/Dispatcher.php
@@ -8,7 +8,6 @@
 namespace bfw;
 
 use bfw\core\Controller;
-use bfw\core\View;
 use ReflectionClass;
 use ReflectionException;
 
@@ -42,16 +41,16 @@
     }
 
     /**
-     * <b>Führt den jeweiligen Controller aus und liefert ein View zurück</b>
+     * <b>Führt den jeweiligen Controller aus</b>
      *
      */
-    public function getView() {
+    public function delegate() {
         $this->request->keepRequestData();
 
         $controllerName = $this->request->get('controller', 'home');
         $action = $this->request->get('action', 'index');
 
-        $class = Controller::mapControllerName($controllerName);
+        $class = Controller::findControllerInNameSpace($controllerName);
 
         try {
             $reflection = new ReflectionClass($class);
@@ -63,18 +62,10 @@
             }
         } catch (ReflectionException $re) {
             $controller = new mvc\controller\ErrorController();
-
-            $controllerName = 'error';
             $action = 'index';
         }
 
-        $controller->$action();
-
-        $view = new View($controller, $controller->getModel());
-        $view->assign('controller', $controllerName);
-        $view->assign('action', $action);
-
-        return $view;
+        return $controller->$action();
     }
 
 }
\ No newline at end of file
--- a/classes/bfw/core/View.php
+++ b/classes/bfw/core/View.php
@@ -38,6 +38,10 @@
         $this->model = $model;
 
         self::$tpl = self::getTemplateEngine();
+
+        $request = $controller->getRequest();
+        $this->assign('controller', $request->get('controller', 'home'));
+        $this->assign('action', $request->get('action', 'index'));
     }
 
     /**
@@ -108,7 +112,9 @@
         $request->setKey('msg', '');
 
         // Fehler wieder auf Null setzen...
-        $request->setKey('fehler', '');
+        $request->setKey('error', '');
+
+        return http_response_code();
     }
 
     public function assign($key, $value) {
--- a/classes/bfw/mvc/controller/BenutzerverwaltungController.php
+++ b/classes/bfw/mvc/controller/BenutzerverwaltungController.php
@@ -26,7 +26,29 @@
      */
     public function meinProfil() {
         $request = $this->getRequest();
+
+        $model = $this->getModel();
+        if ($request->hasPost()) {
+            $input = array(
+                "username" => $request->session('username', ''),
+                'password' => md5($request->session('password', '')),
+                'firstname' => $request->session('firstname', ''),
+                'lastname' => $request->session('lastname', ''),
+            );
+
+            $user = $model->getUser();
+            $user->find($request->getKey('user_id'));
+
+            $user->merge($input);
+            if (!$user->store()) {
+                $request->setKey('error', 'Fehler beim Aktualisieren des Benutzers.');
+            } else {
+                $request->setKey('msg', 'Die Daten wurden aktualisiert.');
+            }
+        }
+
         $view = $this->getView();
+        $view->display();
     }
 
     /**
@@ -34,10 +56,11 @@
      */
     public function abmelden() {
         $request = $this->getRequest();
-        $view = $this->getView();
 
         $request->destroySession();
         $request->initSession();
+
+        Dispatcher::route('/');
     }
 
     /**
@@ -47,6 +70,8 @@
         $request = $this->getRequest();
         $view = $this->getView();
 
+        $this->getView()->display();
+
         if (!$request->hasPost()) {
             // nothing to do!
             return;
@@ -81,6 +106,8 @@
         $model = $this->getModel();
 
         $view->assign('currentUser', $model->getUser());
+
+        $this->getView()->display();
     }
 
     public function index() {
@@ -91,6 +118,10 @@
 
         $group_id = $request->getKey('group_id');
 
+        /**
+         * Hier muss eine ACL-Schicht dazu
+         *
+         */
         if ($group_id != TGroup::ADMIN) {
             Dispatcher::route('/');
         }
@@ -100,5 +131,7 @@
 
         $view->assign('users', $users);
         $view->assign('groups', $groups);
+
+        $this->getView()->display();
     }
 }
--- a/classes/bfw/mvc/controller/DokumentationController.php
+++ b/classes/bfw/mvc/controller/DokumentationController.php
@@ -24,5 +24,7 @@
         $request = $this->getRequest();
         $view = $this->getView();
         $model = $this->getModel();
+
+        $this->getView()->display();
     }
 }
\ No newline at end of file
--- a/classes/bfw/mvc/controller/ErrorController.php
+++ b/classes/bfw/mvc/controller/ErrorController.php
@@ -17,12 +17,14 @@
 
     public function __construct() {
         parent::__construct();
+
+        $this->getView()->assign('controller', 'error');
+        $this->getView()->assign('action', 'index');
     }
 
     public function index() {
-        $request = $this->getRequest();
-        $view = $this->getView();
-        $model = $this->getModel();
+        http_response_code(404);
+        return $this->getView()->display();
     }
 
 }
--- a/classes/bfw/mvc/controller/HomeController.php
+++ b/classes/bfw/mvc/controller/HomeController.php
@@ -23,9 +23,7 @@
      *
      */
     public function index() {
-        $request = $this->getRequest();
-        $view = $this->getView();
-        $model = $this->getModel();
+        $this->getView()->display();
     }
 
 }
\ No newline at end of file
--- a/index.php
+++ b/index.php
@@ -1,14 +1,14 @@
 <?php
 
 /**
- * Ticket-System
+ * Bröker Framework Version 0.1
  *
+ * @author Markus Bröker<broeker.markus@googlemail.com>
  */
 
-namespace bfw;
+use bfw\Dispatcher;
 
 require_once 'config/config.php';
 
 $dispatcher = new Dispatcher();
-$view = $dispatcher->getView();
-$view->display();
\ No newline at end of file
+return $dispatcher->delegate();
\ No newline at end of file