member function getI18n() on null
Describe the bug Uncaught PHP Exception Twig\Error\RuntimeError: "An exception has been thrown during the rendering of a template ("Call to a member function getI18n() on null")." at layout.html.twig line 2
To Reproduce I use lates symfony with dunglas/symfony-docker
Use any custom action
This error has been confirmed. It's a bug that needs to be fixed. Somehow, it's triggered by easyadmin's cache.
This happens on the crud controller pages.
If you clear your cache and restart the frankenphp server, the crud controllers will work fine.
If you visit the /dashboard route and then revisit a crud controller, the error returns back
I was able to find a solution that works. It seems easyadmin doesn't prioritize Legacy Admin URLs anymore
The first solution was to switch to using Pretty Admin Url
The error logged was:
Since easycorp/easyadmin-bundle 4.14.0: Not using pretty admin URLs is deprecated because they will become the only available URLs starting from EasyAdmin 5.0.0. Read the docs to learn how to enable pretty URLs in your application
This come with the disadvantage of renaming any of the crud controller that has the same class name or file name even if the namespaces are different. If like me, you had too many files with same class name but different namespace, then you have a lot of renaming to do!!! :)
For simplicity, change the following class files (format):
App\Admin\UserCrudController
App\Client\UserCrudController
By adding a prefix to the base class:
App\Admin\AdminUserCrudController
App\Client\ClientUserCrudController
The second solution is to dump the autoload (if it is cached)
Since it's a cache problem and most likely occurs in production, I shifted some of the Dockerfile (frankenphp_prod) logic into the frankenphp/docker-entrypoint.sh
if [ -z "$(ls -A 'vendor/' 2>/dev/null)" ]; then
composer install --prefer-dist --no-progress --no-interaction
fi
# After the above line of code in docker-entrypoint.sh
# I added the follow code below
if [ $APP_ENV = "prod" ]; then
# Dump production autoload file
composer dump-autoload --classmap-authoritative --no-dev;
if [ ! -f ".env.local.php" ]; then
# Dump production environmental variables
composer dump-env prod;
fi
fi
Then rebuild the container This solved the problem even for the bug at #6848
Let me know if it worked for you as well
This bug started after > 4.20.3v in prodaction
see https://github.com/EasyCorp/EasyAdminBundle/issues/6873#issuecomment-2746406760