EasyAdminBundle: [3.0.0-dev] Variable "ea" does not exist.

Variable “ea” does not exist. I’m following , https://symfony.com/doc/master/bundles/EasyAdminBundle/index.html UPGRADED FROM 2 TO 3, by following: https://symfony.com/doc/master/bundles/EasyAdminBundle/upgrade.html

And created my dashboard using https://symfony.com/doc/master/bundles/EasyAdminBundle/dashboards.html at https://symfony.com/doc/master/bundles/EasyAdminBundle/dashboards.html#dashboard-route

This is my first run after upgrading to 3.0. Throws error: Variable “ea” does not exist.

and debug toolbar error log is: | Uncaught PHP Exception Twig\Error\RuntimeError: "Variable "ea" does not exist." at /project/vendor/easycorp/easyadmin-bundle/src/Resources/views/layout.html.twig line 2 { "exception": {} } -- | -- At line 2 in layout.html.twig: {% trans_default_domain ea.i18n.translationDomain %}

composer: “easycorp/easyadmin-bundle”: “3.0.x-dev”

I don’t have any yaml config files.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (24 by maintainers)

Most upvoted comments

Solution: Update Symfony to 5.1 so its works by me.

Got the same problem with a simple native Symfony AbstractController that renders a template which extends @EasyAdmin/layout.html.twig. The ea twig global injection and other magic happens in the AdminContextListener. First check there is if the controller is a EasyAdmin controller (DashboardControllerInterface).

Extending AbstractDashboardController instead of AbstractController fixed it for me. No problem for that part of my application so far. You can also just implement DashboardControllerInterfaceand add the required methods. I added an example … did it anyway.

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

final class IndexController extends AbstractDashboardController
{
    /**
     * @Route("/", name="app", methods={"GET"})
     */
    public function index(): Response
    {
        return $this->render('index.html.twig');
    }
}
{# index.html.twig #}
{% extends '@EasyAdmin/layout.html.twig' %}

{% set _content_title = 'Dashboard' %}

{% block page_title -%}{{ _content_title }}{%- endblock %}

{% block content_header %}
    <h1 class="title">{{ _content_title }}</h1>
{% endblock content_header %}

{% block main %}Hi{% endblock main %}
<?php

declare(strict_types=1);

namespace App\Controller;

use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment;

final class IndexController implements DashboardControllerInterface
{
    private Environment $twig;

    public function __construct(Environment $twig)
    {
        $this->twig = $twig;
    }

    /**
     * @Route("/", name="app", methods={"GET"})
     */
    public function index(): Response
    {
        return new Response($this->twig->render('index.html.twig'));
    }

    public function configureDashboard(): Dashboard
    {
        return Dashboard::new();
    }

    public function configureAssets(): Assets
    {
        return Assets::new();
    }

    public function configureMenuItems(): iterable
    {
        return new \ArrayIterator();
    }

    public function configureUserMenu(UserInterface $user): UserMenu
    {
        return UserMenu::new();
    }

    public function configureCrud(): Crud
    {
        return Crud::new();
    }

    public function configureActions(): Actions
    {
        return Actions::new();
    }

    public function configureFilters(): Filters
    {
        return Filters::new();
    }
}

Yes it worked for me too. Updated to Symfony v5.1. So, I’m closing this. Thanks to all.

Is it a bug? Or symfony missconfiguration? @javiereguiluz

@rogergerecke I got the same error first. Here is the point to follow.

  1. Run this: console debug:event-dispatcher
  2. On the above result at : “kernel.controller” event 2.1 Check EasyCorp\Bundle\EasyAdminBundle\EventListener\AdminContextListener::onKernelController() Exist or not.
  3. Then cache clear. It worked for me.

Ok work. After cache clear

I just migrated my old Easyadmin 2.3.7 to 3.x alpha 7 with latest Symfony 5.0.8 and the same error

image