index template

This commit is contained in:
2024-12-12 12:41:45 +03:00
parent 1e566481f7
commit f7253bafe9
9 changed files with 32 additions and 190 deletions

View File

@ -1,104 +0,0 @@
<?php
namespace kernel\app_modules\ЕÑtest\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\ЕÑtest\models\forms\CreateЕÑtestForm;
use kernel\app_modules\ЕÑtest\models\ЕÑtest;
use kernel\app_modules\ЕÑtest\services\ЕÑtestService;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\menu\service\MenuService;
use kernel\Request;
class ЕÑtestController extends AdminController
{
private ЕÑtestService $ЕÑtestService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/ЕÑtest/views/";
$this->ЕÑtestService = new ЕÑtestService();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
$ЕÑtestForm = new CreateЕÑtestForm();
$ЕÑtestForm->load($_REQUEST);
if ($ЕÑtestForm->validate()){
$ЕÑtest = $this->ЕÑtestService->create($ЕÑtestForm);
if ($ЕÑtest){
$this->redirect("/admin/ЕÑtest/view/" . $ЕÑtest->id);
}
}
$this->redirect("/admin/ЕÑtest/create");
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$ЕÑtest = ЕÑtest::find($id);
if (!$ЕÑtest){
throw new Exception(message: "The ЕÑtest not found");
}
$this->cgView->render("view.php", ['ЕÑtest' => $ЕÑtest]);
}
/**
* @throws Exception
*/
public function actionUpdate($id): void
{
$model = ЕÑtest::find($id);
if (!$model){
throw new Exception(message: "The ЕÑtest not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws Exception
*/
public function actionEdit($id): void
{
$ЕÑtest = ЕÑtest::find($id);
if (!$ЕÑtest){
throw new Exception(message: "The ЕÑtest not found");
}
$ЕÑtestForm = new CreateЕÑtestForm();
$ЕÑtestService = new ЕÑtestService();
$ЕÑtestForm->load($_REQUEST);
if ($ЕÑtestForm->validate()) {
$ЕÑtest = $ЕÑtestService->update($ЕÑtestForm, $ЕÑtest);
if ($ЕÑtest) {
$this->redirect("/admin/ЕÑtest/view/" . $ЕÑtest->id);
}
}
$this->redirect("/admin/ЕÑtest/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
{
$ЕÑtest = ЕÑtest::find($id)->first();
$ЕÑtest->delete();
$this->redirect("/admin/ЕÑtest/");
}
}

View File

@ -1,20 +0,0 @@
<?php
use kernel\App;
use kernel\CgRouteCollector;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "ЕÑtest"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionIndex']);
App::$collector->get('/create', [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionView']);
App::$collector->any('/update/{id}', [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\ЕÑtest\controllers\ЕÑtestController::class, 'actionDelete']);
});
});
});

View File

@ -1,31 +0,0 @@
<?php
namespace kernel\app_modules\ЕÑtest;
use kernel\helpers\Debug;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
class ЕÑtestModule extends Module
{
public MenuService $menuService;
public function __construct()
{
$this->menuService = new MenuService();
}
public function init(): void
{
$this->menuService->createItem([
"label" => "ТеÑ<EFBFBD>Ñ",
"url" => "/admin/ЕÑtest",
"slug" => "ЕÑtest",
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("ЕÑtest");
}
}