Implement Product in EasyAdmin
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/Controller/Admin/DashboardController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/Controller/Admin/DashboardController.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace App\Controller\Admin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Entity\Product;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
 | 
				
			||||||
 | 
					use Symfony\Component\HttpFoundation\Response;
 | 
				
			||||||
 | 
					use Symfony\Component\Routing\Annotation\Route;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class DashboardController extends AbstractDashboardController
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function __construct(private AdminUrlGenerator $adminUrlGenerator)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[Route('/admin', name: 'admin')]
 | 
				
			||||||
 | 
					    public function index(): Response
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										36
									
								
								src/Controller/Admin/ProductCrudController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/Controller/Admin/ProductCrudController.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace App\Controller\Admin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Entity\Product;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
 | 
				
			||||||
 | 
					use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ProductCrudController extends AbstractCrudController
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static function getEntityFqcn(): string
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return Product::class;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function configureFields(string $pageName): iterable
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $fields = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        switch ($pageName) {
 | 
				
			||||||
 | 
					            case Crud::PAGE_INDEX:
 | 
				
			||||||
 | 
					            case Crud::PAGE_DETAIL:
 | 
				
			||||||
 | 
					                $fields[] = IdField::new('id');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $fields[] = BooleanField::new('enabled');
 | 
				
			||||||
 | 
					        $fields[] = TextField::new('name');
 | 
				
			||||||
 | 
					        $fields[] = TextEditorField::new('description');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $fields;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -11,6 +11,6 @@ class TestController extends AbstractController
 | 
				
			|||||||
    #[Route('/1')]
 | 
					    #[Route('/1')]
 | 
				
			||||||
    public function test1()
 | 
					    public function test1()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->render('base.html.twig');
 | 
					        return $this->render('base/base.html.twig');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -20,7 +20,7 @@ class Product
 | 
				
			|||||||
    private $name;
 | 
					    private $name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[ORM\Column(type: 'text', nullable: true)]
 | 
					    #[ORM\Column(type: 'text', nullable: true)]
 | 
				
			||||||
    private $Description;
 | 
					    private $description;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getId(): ?int
 | 
					    public function getId(): ?int
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -41,12 +41,12 @@ class Product
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function getDescription(): ?string
 | 
					    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;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,25 +16,7 @@
 | 
				
			|||||||
    {% endblock %}
 | 
					    {% endblock %}
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
 | 
					{% include 'base/navbar.html.twig' %}
 | 
				
			||||||
    <div class="container-fluid">
 | 
					 | 
				
			||||||
        <i class="bi-shop" style="font-size: 2rem; padding-right: 0.5rem; color: white;"></i>
 | 
					 | 
				
			||||||
        <a class="navbar-brand" href="#">IceCold</a>
 | 
					 | 
				
			||||||
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
 | 
					 | 
				
			||||||
            <span class="navbar-toggler-icon"></span>
 | 
					 | 
				
			||||||
        </button>
 | 
					 | 
				
			||||||
        <div class="collapse navbar-collapse" id="navbarCollapse">
 | 
					 | 
				
			||||||
            <ul class="navbar-nav me-auto mb-2 mb-md-0">
 | 
					 | 
				
			||||||
                <li class="nav-item">
 | 
					 | 
				
			||||||
                    <a class="nav-link active" aria-current="page" href="#">Home</a>
 | 
					 | 
				
			||||||
                </li>
 | 
					 | 
				
			||||||
                <li class="nav-item">
 | 
					 | 
				
			||||||
                    <a class="nav-link" href="#">Link</a>
 | 
					 | 
				
			||||||
                </li>
 | 
					 | 
				
			||||||
            </ul>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
</nav>
 | 
					 | 
				
			||||||
<main>
 | 
					<main>
 | 
				
			||||||
    {% block body %}
 | 
					    {% block body %}
 | 
				
			||||||
    {% endblock %}
 | 
					    {% endblock %}
 | 
				
			||||||
							
								
								
									
										19
									
								
								templates/base/navbar.html.twig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								templates/base/navbar.html.twig
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
 | 
				
			||||||
 | 
					    <div class="container-fluid">
 | 
				
			||||||
 | 
					        <i class="bi-shop" style="font-size: 2rem; padding-right: 0.5rem; color: white;"></i>
 | 
				
			||||||
 | 
					        <a class="navbar-brand" href="#">IceCold</a>
 | 
				
			||||||
 | 
					        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
 | 
				
			||||||
 | 
					            <span class="navbar-toggler-icon"></span>
 | 
				
			||||||
 | 
					        </button>
 | 
				
			||||||
 | 
					        <div class="collapse navbar-collapse" id="navbarCollapse">
 | 
				
			||||||
 | 
					            <ul class="navbar-nav me-auto mb-2 mb-md-0">
 | 
				
			||||||
 | 
					                <li class="nav-item">
 | 
				
			||||||
 | 
					                    <a class="nav-link active" aria-current="page" href="#">Home</a>
 | 
				
			||||||
 | 
					                </li>
 | 
				
			||||||
 | 
					                <li class="nav-item">
 | 
				
			||||||
 | 
					                    <a class="nav-link" href="{{ path('admin') }}">Admin</a>
 | 
				
			||||||
 | 
					                </li>
 | 
				
			||||||
 | 
					            </ul>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</nav>
 | 
				
			||||||
		Reference in New Issue
	
	Block a user