Added path function
This commit is contained in:
parent
03a3d6659e
commit
e38f7d106e
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@ cache/*
|
||||
vendor/
|
||||
webcron.old/config.inc.php
|
||||
\.idea/
|
||||
.env
|
||||
.env
|
||||
storage/database.sqlite
|
@ -18,8 +18,7 @@ abstract class Controller
|
||||
|
||||
public function __construct(Request $request, Kernel $kernel)
|
||||
{
|
||||
$loader = new FilesystemLoader([$kernel->getTemplateDir()]);
|
||||
$this->twig = new Environment($loader);
|
||||
$this->twig = new Twig($kernel);
|
||||
$this->request = $request;
|
||||
$this->kernel = $kernel;
|
||||
}
|
||||
|
37
lib/Framework/Twig.php
Normal file
37
lib/Framework/Twig.php
Normal file
@ -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>
|
||||
<div class="col-md-4 col-md-offset-4 col-xs-12">
|
||||
<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 == "" %}
|
||||
<div class="alert alert-danger fade in">
|
||||
<a href="#" class="close" data-dismiss="alert">×</a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user