# HG changeset patch # User Markus Bröker # Date 1447465373 -3600 # Node ID 7fddaf017915f2222b5c198e517caadd160973c5 # Parent ef2914b7af7881248a905af4f9c125b106a2800d Die View erzeugt das UI und nicht mehr der Dispatcher diff --git a/classes/bfw/Dispatcher.php b/classes/bfw/Dispatcher.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 @@ } /** - * Führt den jeweiligen Controller aus und liefert ein View zurück + * Führt den jeweiligen Controller aus * */ - 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 diff --git a/classes/bfw/core/View.php b/classes/bfw/core/View.php --- 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) { 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 @@ -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(); } } 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 @@ -24,5 +24,7 @@ $request = $this->getRequest(); $view = $this->getView(); $model = $this->getModel(); + + $this->getView()->display(); } } \ 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 @@ -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(); } } 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 @@ -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 diff --git a/index.php b/index.php --- a/index.php +++ b/index.php @@ -1,14 +1,14 @@ */ -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