104 lines
2.8 KiB
PHP
104 lines
2.8 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace kernel\app_modules\Е<>test\controllers;
|
|||
|
|
|||
|
use Exception;
|
|||
|
use JetBrains\PhpStorm\NoReturn;
|
|||
|
use kernel\AdminController;
|
|||
|
use kernel\app_modules\Е<>test\models\forms\CreateЕ<65>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 Е<EFBFBD>testController extends AdminController
|
|||
|
{
|
|||
|
private Е<EFBFBD>testService $Е<>testService;
|
|||
|
protected function init(): void
|
|||
|
{
|
|||
|
parent::init();
|
|||
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/Е<>test/views/";
|
|||
|
$this->Е<EFBFBD>testService = new Е<EFBFBD>testService();
|
|||
|
}
|
|||
|
|
|||
|
public function actionCreate(): void
|
|||
|
{
|
|||
|
$this->cgView->render("form.php");
|
|||
|
}
|
|||
|
|
|||
|
#[NoReturn] public function actionAdd(): void
|
|||
|
{
|
|||
|
$Е<>testForm = new CreateЕ<EFBFBD>testForm();
|
|||
|
$Е<>testForm->load($_REQUEST);
|
|||
|
if ($Е<>testForm->validate()){
|
|||
|
$Е<>test = $this->Е<EFBFBD>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 = Е<EFBFBD>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 = Е<EFBFBD>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 = Е<EFBFBD>test::find($id);
|
|||
|
if (!$Е<>test){
|
|||
|
throw new Exception(message: "The Е<>test not found");
|
|||
|
}
|
|||
|
$Е<>testForm = new CreateЕ<EFBFBD>testForm();
|
|||
|
$Е<>testService = new Е<EFBFBD>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 = Е<EFBFBD>test::find($id)->first();
|
|||
|
$Е<>test->delete();
|
|||
|
$this->redirect("/admin/Е<>test/");
|
|||
|
}
|
|||
|
}
|