Home > Blockchain >  EasyAdmin and Symfony 6 - AbstractDashboardController missing
EasyAdmin and Symfony 6 - AbstractDashboardController missing

Time:06-10

I'm trying to set up Easy Admin 4 with Symfony 6, so I did composer require easycorp/easyadmin-bundle as the documentation says.

Composer create DashboardController.php and I have the following code :

<?php

namespace App\Controller\Admin;

use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DashboardController extends AbstractDashboardController
{
    #[Route('/admin', name: 'admin')]
    public function index(): Response
    {
        return parent::index();

        // Option 1. You can make your dashboard redirect to some common page of your backend
        //
        // $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);
        // return $this->redirect($adminUrlGenerator->setController(OneOfYourCrudController::class)->generateUrl());

        // Option 2. You can make your dashboard redirect to different pages depending on the user
        //
        // if ('jane' === $this->getUser()->getUsername()) {
        //     return $this->redirect('...');
        // }

        // Option 3. You can render some custom template to display a proper dashboard with widgets, etc.
        // (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig)
        //
        // return $this->render('some/path/my-dashboard.html.twig');
    }

    public function configureDashboard(): Dashboard
    {
        return Dashboard::new()
            ->setTitle('La boutique Française');
    }

    public function configureMenuItems(): iterable
    {
        yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
        // yield MenuItem::linkToCrud('Utilisateurs', 'fas fa-list', User::class);
    }
}

Now, AbstractDashboardController is underlined in red avec got this warning : Undefined type 'EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController'

as AbstractDashboardController is missing, the return parent::... does not work neither, as the Dashboard class etc.

Any idea how to fix this ? Didn't find any answer on other posts.

Thank you !

CodePudding user response:

first of all, parent::index(); will only show you the default index page of the package. Like it's said in the function's comment, you have to choose what you want to return. For example, for now, my index function is only :

return $this->render('admin/dashboard.html.twig');

Where my twig file contains :

{% extends '@EasyAdmin/layout.html.twig' %}

However, your file looks good (I've the same things). Maybe doing a php bin/console cache:clear and a server restart will resolve your issue ?

  • Related