backend/index.php

56 lines
2.6 KiB
PHP
Raw Normal View History

2024-07-03 14:41:15 +03:00
<?php
2024-07-08 16:20:25 +03:00
error_reporting(-1);
ini_set("display_errors", true);
2024-07-03 14:41:15 +03:00
require_once "vendor/autoload.php";
require 'bootstrap.php';
2024-07-03 15:15:59 +03:00
use app\controllers\MainController;
2024-07-09 16:08:50 +03:00
use app\controllers\UserController;
use app\controllers\QuestionController;
use app\controllers\AnswerController;
use app\controllers\PostController;
use app\helpers\Debug;
2024-07-03 14:41:15 +03:00
use Phroute\Phroute\RouteCollector;
2024-07-03 15:15:59 +03:00
$router = new RouteCollector();
$router->get('/', [MainController::class, 'actionIndex']);
$router->get('/example', [MainController::class, 'actionExample']);
2024-07-08 16:20:25 +03:00
$router->group(["prefix" => "admin"], function (RouteCollector $router){
$router->group(["prefix" => "user"], function (RouteCollector $router){
$router->get('/', [\app\controllers\UserController::class, 'actionIndex']);
2024-07-24 16:29:00 +03:00
$router->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
2024-07-09 16:08:50 +03:00
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
2024-07-24 16:29:00 +03:00
$router->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
// $router->get('/{id}/update', [\app\controllers\UserController::class, 'actionUpdate']);
$router->any('/update/{id}', [\app\controllers\UserController::class, 'actionUpdate']);
$router->any("/edit/{id}", [\app\controllers\UserController::class, 'actionEdit']);
$router->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']);
2024-07-08 16:20:25 +03:00
});
2024-07-12 11:31:04 +03:00
$router->group(["prefix" => "question"], function (RouteCollector $router){
$router->get('/create', [QuestionController::class, 'actionCreate']);
$router->get('/update', [QuestionController::class, 'actionUpdate']);
$router->get('/delete/{id}', [QuestionController::class, 'actionDelete']);
$router->get('/', [QuestionController::class, 'actionIndex']);
$router->get('/{id}', [QuestionController::class, 'actionView']);
$router->post("/", [QuestionController::class, 'actionAdd']);
$router->post("/edit", [QuestionController::class, 'actionEdit']);
});
$router->group(["prefix" => "post"], function (RouteCollector $router){
$router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
});
2024-07-08 16:20:25 +03:00
});
2024-07-09 16:08:50 +03:00
$router->get('/allQuestions', [QuestionController::class, 'actionViewAllQuestions']);
2024-07-08 16:20:25 +03:00
2024-07-09 16:08:50 +03:00
$router->get('/allAnswers', [AnswerController::class, 'actionViewAllAnswers']);
2024-07-05 13:49:04 +03:00
2024-07-03 15:15:59 +03:00
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// Print out the value returned from the dispatched function
echo $response;