Esempio n. 1
0
 /**
  * Dispatchs the request
  */
 public function dispatch()
 {
     $this->variables = array_merge($this->variables, array('method' => $_SERVER['REQUEST_METHOD']));
     $code = 404;
     foreach ($this->routes as $path => $action) {
         if (is_array($params = $this->routeMatch($path))) {
             list($ctrl, $action) = explode('#', $action);
             $ctrl_class = 'Controller\\' . $ctrl;
             /** @var Controller\Base $ctrl_inst */
             $ctrl_inst = new $ctrl_class();
             $ctrl_inst->setVariables($this->variables);
             try {
                 if (method_exists($ctrl_inst, $action . 'Action')) {
                     $template_params = $ctrl_inst->{$action . 'Action'}($params);
                 } else {
                     $template_params = array();
                 }
                 $renderer = new TemplateRenderer($ctrl, $action);
                 $params = array_merge($this->variables, $template_params ?: array());
                 if ($action == 'historiqueAchat') {
                     echo $renderer->render($params);
                 } else {
                     $renderer->renderWithLayout($params);
                 }
                 return;
             } catch (Controller\Exception\Base $e) {
                 break;
             } catch (\Exception $e) {
                 file_put_contents('res/log/error.log', $e->getMessage());
                 $code = 500;
                 break;
             }
         }
     }
     $renderer = new TemplateRenderer('Error', $code);
     $renderer->renderWithLayout($this->variables);
 }
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     return $this->renderer->render($this->data, $this->loader);
 }
Esempio n. 3
0
/**
 * Renders a partial template in View/. The view name must be underscore-prefixed
 *
 * @param string $name Like "controller/action" (will find View/controller/_action.php)
 * @param string[] $vars
 * @return string Rendered template
 */
function partial($name, $vars)
{
    list($ctrl, $action) = explode('/', $name);
    $renderer = new TemplateRenderer($ctrl, '_' . $action);
    return $renderer->render($vars);
}