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')]
|
||||
public function test1()
|
||||
{
|
||||
return $this->render('base.html.twig');
|
||||
return $this->render('base/base.html.twig');
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user