/** * Renders actions output * * @param string|null $view * @throws \Exception */ protected function render($view = null) { if (empty($view) && !$this->rendered) { $view = $this->action; } $this->rendered = true; if (empty($view)) { $controller = get_class($this); throw new \Exception("Empty view path supplied to {$controller}::render"); } $view = 'controllers/' . $this->name . '/' . $view; $this->vars = array_merge($this->vars, ['app' => $this->app]); $output = $this->view->fetch($view, (array) $this->vars); $layout_vars = ['app' => $this->app, 'content' => $output]; if (!empty($this->vars['layout_title'])) { $layout_vars['layout_title'] = $this->vars['layout_title']; } else { $layout_vars['layout_title'] = Inflector::titleize($this->action); } $layout_vars['layout_breadcrumbs'] = ['app' => $this->app->getName(), 'controller' => Inflector::titleize($this->name)]; if ($this->action != 'index') { $layout_vars['layout_breadcrumbs']['action'] = $layout_vars['layout_title']; } $layout_vars['layout_shortcuts'] = Projects::getShortcuts(); if (!empty($this->vars['layout_breadcrumbs'])) { $layout_vars['layout_breadcrumbs'] = array_merge($layout_vars['layout_breadcrumbs'], (array) $this->vars['layout_breadcrumbs']); } $this->view->display('layouts/' . $this->layout, $layout_vars); }
<?php // Initialize the autoloader require '/vagrant/src/autoload.php'; use Dashbrew\Dashboard\Application; use Dashbrew\Dashboard\Controller\ControllerCollection; use Dashbrew\Dashboard\View; // Initialize the application $app = new Application(['debug' => true, 'view' => new View(), 'templates.path' => __DIR__ . '/views']); $app->setName('Dashbrew'); $collection = new ControllerCollection($app, 'Dashbrew\\Dashboard\\Controllers'); $collection->addRoutes('home', ['/']); $collection->addRoutes('projects'); $collection->addRoutes('server'); $app->run();