Beispiel #1
0
 /**
  * Inits the route for page rendering, registers a layout renderer and 
  * provides fancy error pages
  *
  * @return void
  */
 function init()
 {
     $routes = $this->import("Routes");
     $app = $this->import("App");
     $config = $this->import("Config");
     $routes->addRoute(new PageRoute(array($this, "render")));
     Page::setSearchPath(array($this->getPath() . "/default", \Core\APPROOT . "/pages"));
     // An object which holds the layout variables
     $layout = new StdClass();
     $this->export("Layout", $layout);
     $layout->title = "Willkommen zu SimpleCMS!";
     $layoutRenderer = new Mustache();
     $layoutRenderer->setTemplatePath($this->getPath() . "/default")->setTemplatePath(\Core\APPROOT . "/layouts");
     $layoutName = isset($config["Pages"]["layout_name"]) ? $config["Pages"]["layout_name"] : "layout";
     // Render the layout after the dispatching process
     $app->after(function ($request, $response) use($layoutName, $layout, $layoutRenderer) {
         $body = $response->getBody();
         $layout->content = $body;
         $response->setBody($layoutRenderer->render($layoutName, $layout));
     });
     // Checks if the response has errors and renders appropiate error pages
     $app->error(new ErrorHandler());
 }