Erster Stand des mvc-Frameworks
This commit is contained in:
78
rendering/Controller/FrontendController.php
Normal file
78
rendering/Controller/FrontendController.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by CS medien- & kommunikationssysteme.
|
||||
* @author Christian Steinle
|
||||
* @date 03.08.2016
|
||||
*
|
||||
* @copyright CS medien- & kommunikationssysteme (http://www.steinle-computer.de)
|
||||
*/
|
||||
|
||||
namespace Controller;
|
||||
|
||||
use Helper\Database;
|
||||
use Model\NavigationModel;
|
||||
use View\StandardView;
|
||||
use View\NavigationView;
|
||||
|
||||
class FrontendController
|
||||
{
|
||||
protected $route = '';
|
||||
|
||||
protected $request = array();
|
||||
|
||||
protected $contents = array();
|
||||
|
||||
public function __construct($route, array $request)
|
||||
{
|
||||
$this->route = $route;
|
||||
$this->routeParts = explode('/', $route);
|
||||
$this->request = $request;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
|
||||
private function init()
|
||||
{
|
||||
NavigationModel::init($this->routeParts);
|
||||
$navigation = new NavigationView(NavigationModel::getData(), $this->routeParts);
|
||||
|
||||
$this->contents['title'] = 'AHD Allradhaus';
|
||||
$this->contents['navigation'] = $navigation->getHtml();
|
||||
|
||||
$this->contents['headline'] = NavigationModel::getHeadline();
|
||||
$this->contents['content'] = '';
|
||||
$tmpContents = NavigationModel::getContents();
|
||||
|
||||
/**
|
||||
* @var Database $modelClass
|
||||
*/
|
||||
foreach ($tmpContents as $key => $data)
|
||||
{
|
||||
$modelClass = 'Model\\' . $data['Controller'] . 'Model';
|
||||
$viewClass = 'View\\' . $data['Controller'] . 'View';
|
||||
if (class_exists($modelClass, true))
|
||||
{
|
||||
$modelData = $modelClass::getItem($data['ID']);
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* TODO: ErrorHandler bauen
|
||||
*/
|
||||
return;
|
||||
}
|
||||
if (class_exists($viewClass, true))
|
||||
{
|
||||
$dataView = new $viewClass($modelData, $data['Controller']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dataView = new StandardView($modelData, $data['Controller']);
|
||||
}
|
||||
$this->contents['content'] .= $dataView->render();
|
||||
}
|
||||
|
||||
$pageView = new StandardView($this->contents, 'index');
|
||||
echo $pageView->render();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user