This commit is contained in:
Билай Станислав 2024-07-25 11:55:31 +03:00
parent f005cb357b
commit 4d922096a9
3 changed files with 41 additions and 16 deletions

View File

@ -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/");
}
}

View File

@ -8,7 +8,7 @@ class PrimaryBtn
public function __construct(string $title, string $url)
{
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: 100px;' >$title</a>";
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: 150px;' >$title</a>";
}
public function fetch(): string

22
views/admin/user/view.php Normal file
View File

@ -0,0 +1,22 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $user
*/
use Itguild\Tables\ViewJsonTable;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\ViewJsonTableEloquentModel;
$dataProvider = new ViewJsonTableEloquentModel($user, [
'params' => ["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();