From ce7bd7a3eb30d2637f618b227b23bd06fff0102e Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 29 Dec 2021 01:03:08 +0100 Subject: [PATCH] Implement Product in EasyAdmin --- src/Controller/Admin/DashboardController.php | 39 +++++++++++++++++++ .../Admin/ProductCrudController.php | 36 +++++++++++++++++ src/Controller/TestController.php | 2 +- src/Entity/Product.php | 8 ++-- templates/{ => base}/base.html.twig | 20 +--------- templates/base/navbar.html.twig | 19 +++++++++ 6 files changed, 100 insertions(+), 24 deletions(-) create mode 100644 src/Controller/Admin/DashboardController.php create mode 100644 src/Controller/Admin/ProductCrudController.php rename templates/{ => base}/base.html.twig (58%) create mode 100644 templates/base/navbar.html.twig diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php new file mode 100644 index 0000000..b2e9007 --- /dev/null +++ b/src/Controller/Admin/DashboardController.php @@ -0,0 +1,39 @@ +redirect($this->adminUrlGenerator->setController(ProductCrudController::class)->generateUrl()); + } + + public function configureDashboard(): Dashboard + { + return Dashboard::new() + ->setTitle('IceCold'); + } + + public function configureMenuItems(): iterable + { +// yield MenuItem::linktoRoute('Back to home', 'fas fa-home', 'home'); + + yield MenuItem::section('Products', 'fas fa-folder-open'); + yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home'); + yield MenuItem::linkToCrud('Products', 'fas fa-list', Product::class); + } +} diff --git a/src/Controller/Admin/ProductCrudController.php b/src/Controller/Admin/ProductCrudController.php new file mode 100644 index 0000000..0521f64 --- /dev/null +++ b/src/Controller/Admin/ProductCrudController.php @@ -0,0 +1,36 @@ +render('base.html.twig'); + return $this->render('base/base.html.twig'); } } \ No newline at end of file diff --git a/src/Entity/Product.php b/src/Entity/Product.php index 5daba94..57ff2ef 100644 --- a/src/Entity/Product.php +++ b/src/Entity/Product.php @@ -20,7 +20,7 @@ class Product private $name; #[ORM\Column(type: 'text', nullable: true)] - private $Description; + private $description; public function getId(): ?int { @@ -41,12 +41,12 @@ class Product public function getDescription(): ?string { - return $this->Description; + return $this->description; } - public function setDescription(?string $Description): self + public function setDescription(?string $description): self { - $this->Description = $Description; + $this->description = $description; return $this; } diff --git a/templates/base.html.twig b/templates/base/base.html.twig similarity index 58% rename from templates/base.html.twig rename to templates/base/base.html.twig index aca8ed3..900466b 100644 --- a/templates/base.html.twig +++ b/templates/base/base.html.twig @@ -16,25 +16,7 @@ {% endblock %} - +{% include 'base/navbar.html.twig' %}
{% block body %} {% endblock %} diff --git a/templates/base/navbar.html.twig b/templates/base/navbar.html.twig new file mode 100644 index 0000000..9858a79 --- /dev/null +++ b/templates/base/navbar.html.twig @@ -0,0 +1,19 @@ + \ No newline at end of file