From 4d922096a9231b84e968ea6ca35e5bd0776dd1e5 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 25 Jul 2024 11:55:31 +0300 Subject: [PATCH] btn --- app/controllers/UserController.php | 33 ++++++++++++++++-------------- kernel/IGTabel/btn/PrimaryBtn.php | 2 +- views/admin/user/view.php | 22 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 views/admin/user/view.php diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index e97aabd..a478284 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -75,20 +75,21 @@ class UserController extends Controller{ if (!$user){ throw new Exception(message: "The user not found"); } - $this->twig->addFunction(new TwigFunction('table', function () use ($user){ - $dataProvider = new ViewJsonTableEloquentModel($user, [ - 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/user", - ]); - $table = new ViewJsonTable($dataProvider->getJson()); - $table->beforeTable(function (){ - return PrimaryBtn::create("Список", "/admin/user")->fetch(); - }); - $table->create(); - $table->render(); - })); - - echo $this->twig->render('user_table.html.twig'); +// $this->twig->addFunction(new TwigFunction('table', function () use ($user){ +// $dataProvider = new ViewJsonTableEloquentModel($user, [ +// 'params' => ["class" => "table table-bordered", "border" => "2"], +// 'baseUrl' => "/admin/user", +// ]); +// $table = new ViewJsonTable($dataProvider->getJson()); +// $table->beforeTable(function (){ +// return PrimaryBtn::create("Список", "/admin/user")->fetch(); +// }); +// $table->create(); +// $table->render(); +// })); +// +// echo $this->twig->render('user_table.html.twig'); + $this->cgView->render("user/view.php", ['user' => $user]); } /** @@ -98,7 +99,7 @@ class UserController extends Controller{ */ public function actionUpdate($id): void { - echo $this->twig->render('user_update.html.twig'); + $this->cgView->render("user/form.php"); } public function actionEdit($id): void @@ -135,6 +136,8 @@ class UserController extends Controller{ public function actionDelete($id): void { User::find($id)->delete(); + $this->redirect("/admin/user/"); + } } \ No newline at end of file diff --git a/kernel/IGTabel/btn/PrimaryBtn.php b/kernel/IGTabel/btn/PrimaryBtn.php index f4312c4..31a43c3 100644 --- a/kernel/IGTabel/btn/PrimaryBtn.php +++ b/kernel/IGTabel/btn/PrimaryBtn.php @@ -8,7 +8,7 @@ class PrimaryBtn public function __construct(string $title, string $url) { - $this->btn = "$title"; + $this->btn = "$title"; } public function fetch(): string diff --git a/views/admin/user/view.php b/views/admin/user/view.php new file mode 100644 index 0000000..67e93d3 --- /dev/null +++ b/views/admin/user/view.php @@ -0,0 +1,22 @@ + ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/user", +]); +$table = new ViewJsonTable($dataProvider->getJson()); +$table->beforeTable(function () use ($user) { + $btn = PrimaryBtn::create("Список", "/admin/user")->fetch(); + $btn .= PrimaryBtn::create("Редактировать", "/admin/user/update/" . $user->id)->fetch(); + $btn .= PrimaryBtn::create("Удалить", "/admin/user/delete/" . $user->id)->fetch(); + return $btn; +}); +$table->create(); +$table->render(); \ No newline at end of file