| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- class Controller {
- private $request = null;
- private $template = '';
- private $view = null;
- /**
- *
- * @param Array $request $_GET and $_POST
- */
- public function __construct($request) {
- ErrorHandler::$eh = new ErrorHandler();
- Database::$db = new Database();
- $this->view = new View();
- $this->request = $request;
- if(!empty($request['action']) && $request['action']) { // any action needs to be done?
- $this->actionController();
- }
- $this->template = !empty(strtok($_SERVER['REQUEST_URI'], '?')) ? strtok($_SERVER['REQUEST_URI'], '?') : 'default';
- }
- /**
- * Return requested page
- *
- * @return String Content of requested page
- */
- public function display() {
- $singlePage = false; // set to true if header/footer shouldn't be used
- switch($this->template) {
- case 'default':
- default:
- $singlePage = true;
- $this->view->setTemplate('default');
- $this->view->assign("test", "joo");
- break;
- }
- if(!$singlePage) {
- $headerView = new View();
- $footerView = new View();
- $headerView->setTemplate("header");
- $footerView->setTemplate("footer");
- $header = $headerView->loadTemplate(); // save them in vars to prevent errors being ignored
- $footer = $footerView->loadTemplate();
- $this->view->assign("errors", ErrorHandler::$eh->getErrors()); // get errors as last thing
- return $header . $this->view->loadTemplate() . $footer;
- }
- $this->view->assign("errors", ErrorHandler::$eh->getErrors()); // get errors as last thing
- return $this->view->loadTemplate();
- }
- private function actionController() {
- switch($this->request['action']) {
- default:
- error_log("Unknown action: " . $this->request['action']);
- break;
- }
- }
- }
- ?>
|