Khandaker Toihidul Islam
Software Engineer
Backend : PHP | Mysql | Symfony | CakePhp | Wordpress | Drupal
Frontend : Node js | Vue js | React Js | Javascript | HTML | CSS | Bootstrap
Tools , Server : Nginx | Apache | Git | Jenkins | Jira | Asana | Silenium | Spira

Custom Dashboard in Easy Admin, Symfony 4

  1. Edit config/routes/easy_admin.yaml
easy_admin_bundle:
    resource: 'App\Controller\AdminController'
    prefix: /dashboard
    type: annotation

2. Create Controller inside src/AdminController.php

<?php 
namespace App\Controller;

use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class AdminController extends EasyAdminController
{
    /**
     * @Route("/", name="easyadmin")
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function indexAction(Request $request)
    {
        $this->initialize($request);

        if (null === $request->query->get('entity')) {
            return $this->render('bundles/EasyAdminBundle/default/dashboard.html.twig');
        }

        return parent::indexAction($request);
    }
}

3. Create template templates/bundles/EasyAdminBundle/default/dashboard.html.twig

{# templates/bundles/EasyAdminBundle/default/layout.html.twig #}

{% extends '@!EasyAdmin/default/layout.html.twig' %}
{% block content %}
  Custom dashboard comes to here
{% endblock %}

4. Add menu to config/packages/easy_admin.yaml

    menu:
      - { label: 'Dashboard', route: 'easyadmin', default: true }

Hope for the best.

Thanks,

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *