Added ability to have url parameters

This commit is contained in:
Jeroen De Meerleer 2021-04-08 14:54:30 +02:00
parent bb278e5d17
commit 5cf6ba2e76
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
6 changed files with 42 additions and 7 deletions

View File

@ -1,7 +1,7 @@
default:
path: '/'
defaults:
_controller: JeroenED\Webcron\Controller\DefaultController::defaultAction
_controller: JeroenED\Webcron\Controller\JobController::defaultAction
login:
path: '/login'
@ -13,3 +13,13 @@ login_check:
methods: ['POST']
defaults:
_controller: JeroenED\Webcron\Controller\SecurityController::loginCheckAction
job_index:
path: '/job'
defaults:
_controller: JeroenED\Webcron\Controller\JobController::defaultAction
job_view:
path: '/job/{id}'
defaults:
_controller: JeroenED\Webcron\Controller\JobController::viewAction

View File

@ -28,7 +28,9 @@ class Router
$controller = explode('::', $method['_controller']);
$controllerObj = new ('\\' . $controller[0])($request, $kernel);
$action = $controller[1];
$response = $controllerObj->$action();
unset($method['_controller']);
unset($method['_route']);
$response = $controllerObj->$action(...$method);
if ($response instanceof Response) {
return $response;

View File

@ -30,8 +30,8 @@ class Twig
public function addFunctions()
{
$path = new TwigFunction('path', function(string $route) {
return $this->kernel->getRouter()->getUrlForRoute($route);
$path = new TwigFunction('path', function(string $route, array $params) {
return $this->kernel->getRouter()->getUrlForRoute($route, $params);
});
$this->environment->addFunction($path);

View File

@ -8,9 +8,10 @@ use JeroenED\Webcron\Repository\Job;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller
class JobController extends Controller
{
public function DefaultAction() {
public function DefaultAction()
{
if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) {
return new RedirectResponse($this->generateRoute('login'));
}
@ -18,4 +19,9 @@ class DefaultController extends Controller
$jobs = $jobRepo->getAllJobs();
return $this->render('job/index.html.twig', ['jobs' => $jobs]);
}
public function viewAction($id)
{
return new Response('Not implemented yet', Response::HTTP_TOO_EARLY);
}
}

17
storage/database.sql Normal file
View File

@ -0,0 +1,17 @@
-- job definition
CREATE TABLE job (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT(25) NOT NULL,
"data" TEXT NOT NULL,
delay INTEGER,
nextrun INTEGER,
lastrun INTEGER
);
-- "user" definition
CREATE TABLE "user" (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
email TEXT(50) NOT NULL,
password TEXT(72) NOT NULL
);

View File

@ -24,7 +24,7 @@
<td>{{ job.nextrun | date("d/m/Y H:i:s") }}</td>
<td>
<a href="#" data-id="{{ job.id }}" class="runcron btn btn-default"><span class="glyphicon glyphicon-play"><span></a>
<a href="runs.php?jobID={{ job.id }}" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></a>
<a href="{{ path('job_view', {'id': job.id}) }}" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></a>
<a href="editjob.php?jobID={{ job.id }}" class="btn btn-default"><span class="glyphicon glyphicon-edit"><span></a>
<a onclick="return confirm('Are you sure you want to delete this job?')" href="overview.php?id={{ job.id }}&action=delete" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a>
</td>