Added path function
This commit is contained in:
parent
03a3d6659e
commit
e38f7d106e
|
@ -3,4 +3,5 @@ cache/*
|
||||||
vendor/
|
vendor/
|
||||||
webcron.old/config.inc.php
|
webcron.old/config.inc.php
|
||||||
\.idea/
|
\.idea/
|
||||||
.env
|
.env
|
||||||
|
storage/database.sqlite
|
|
@ -18,8 +18,7 @@ abstract class Controller
|
||||||
|
|
||||||
public function __construct(Request $request, Kernel $kernel)
|
public function __construct(Request $request, Kernel $kernel)
|
||||||
{
|
{
|
||||||
$loader = new FilesystemLoader([$kernel->getTemplateDir()]);
|
$this->twig = new Twig($kernel);
|
||||||
$this->twig = new Environment($loader);
|
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->kernel = $kernel;
|
$this->kernel = $kernel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace JeroenED\Framework;
|
||||||
|
|
||||||
|
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
class Twig
|
||||||
|
{
|
||||||
|
private Environment $environment;
|
||||||
|
private Kernel $kernel;
|
||||||
|
public function __construct(Kernel $kernel)
|
||||||
|
{
|
||||||
|
|
||||||
|
$loader = new FilesystemLoader([$kernel->getTemplateDir()]);
|
||||||
|
$this->environment = new Environment($loader);
|
||||||
|
$this->kernel = $kernel;
|
||||||
|
$this->addFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render(string $template, array $vars = []): string
|
||||||
|
{
|
||||||
|
return $this->environment->render($template, $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addFunctions()
|
||||||
|
{
|
||||||
|
$path = new TwigFunction('path', function(string $route) {
|
||||||
|
return $this->kernel->getRouter()->getUrlForRoute($route);
|
||||||
|
});
|
||||||
|
$this->environment->addFunction($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div class="col-md-4 col-md-offset-4 col-xs-12">
|
<div class="col-md-4 col-md-offset-4 col-xs-12">
|
||||||
<h1>Webcron management</h1>
|
<h1>Webcron management</h1>
|
||||||
<form class="form-horizontal" method="post" action="/login_check">
|
<form class="form-horizontal" method="post" action="{{ path('login_check') }}">
|
||||||
{% if not error == "" %}
|
{% if not error == "" %}
|
||||||
<div class="alert alert-danger fade in">
|
<div class="alert alert-danger fade in">
|
||||||
<a href="#" class="close" data-dismiss="alert">×</a>
|
<a href="#" class="close" data-dismiss="alert">×</a>
|
||||||
|
|
Loading…
Reference in New Issue