Installing EasyAdmin
Well hey friends! We are in for a treat with this tutorial! It's EasyAdmin: my favorite admin generator for Symfony. It just... gives you so many features out of the box. And it looks great! This shouldn't really be a surprise because its creator is the always-impressive Javier Eguiluz.
So let's have some fun and learn how to bend EasyAdmin to our will. Because getting a lot of features for free is great... as long as we can extend it to do crazy things when we need to.
Project Setup
To squeeze the most "easy" out of EasyAdmin, you should definitely code along with me. You probably know the drill: download the course code from this page and unzip it to find a start/ directory with the same code that you see here. Check out the README.md file for all the setup goodies. I've already done all of these steps except for two.
For the first, find your terminal and run:
yarn install
I ran this already to save time... so I'll skip to compiling my assets with:
yarn watch
You can also run:
yarn dev-server
Which can do cool things like update your CSS without refreshing.
Perfect! For the second thing, open up another tab and run:
symfony serve -d
This fires up a local web server - using the Symfony binary - at https://127.0.0.1:8000. I'll be lazy by holding Cmd and clicking the link to pop open my browser. Say "hello" to... Cauldron Overflow! If you've been doing our Symfony 5 series, you're definitely familiar with this project. But, this is a Symfony 6 project, not Symfony 5:
| { | |
| // ... lines 2 - 3 | |
| "require": { | |
| // ... lines 5 - 15 | |
| "symfony/asset": "6.0.*", | |
| "symfony/console": "6.0.*", | |
| "symfony/dotenv": "6.0.*", | |
| // ... line 19 | |
| "symfony/framework-bundle": "6.0.*", | |
| // ... line 21 | |
| "symfony/runtime": "6.0.*", | |
| "symfony/security-bundle": "6.0.*", | |
| "symfony/stopwatch": "6.0.*", | |
| "symfony/twig-bundle": "6.0.*", | |
| // ... line 26 | |
| "symfony/yaml": "6.0.*", | |
| // ... lines 28 - 29 | |
| }, | |
| "require-dev": { | |
| // ... line 32 | |
| "symfony/debug-bundle": "6.0.*", | |
| // ... line 34 | |
| "symfony/var-dumper": "6.0.*", | |
| "symfony/web-profiler-bundle": "6.0.*", | |
| // ... line 37 | |
| }, | |
| // ... lines 39 - 98 | |
| } |
Oooo. If you are using Symfony 5, don't worry: very little will be different.
You don't need to worry too much about the majority of the code inside the project. The most important thing is probably our src/Entity/ directory. Our site has questions, and each Question has a number of answers. Each Question belongs to a single Topic... and then we have a User entity.
Our goal in this tutorial is to create a rich admin section that allows our admin users to manage all of this data.
Installing EasyAdmin
So let's get EasyAdmin installed! Find your terminal and run:
composer require "admin:4.13.*"
Tip
EasyAdmin supports pretty admin URLs since v4.14.0.
To get the URLs used in the tutorial, use v4.13.*.
This is a Flex alias for easycorp/easyadmin-bundle. Notice that it downloads the shiny new version 4 of EasyAdmin, which only works with Symfony 6. So if you're using Symfony 5, run:
composer require admin:^3
to get version 3. Right now, version 4 and version 3 are identical, so you won't notice any differences. But going forward, new features will only be added to version 4.
Cool! Now that this is installed, what's next? Ship it!? Well, before we start deploying and celebrating our success... if we want to actually see something on our site, we're going to need a dashboard. Let's generate that next!
56 Comments
Thank you! :)
If you're on the Symfony 6 track and feel like you're missing a course somewhere, you are. It's this one: https://symfonycasts.com/screencast/symfony-security
Highly recommend you do that course first, before this one, even if it is for Symfony 5. That course covers setting up users, and logins, and many of the things that are just "suddenly there" when this course starts.
Hey Ryan,
Yeah, you're right, it's good to know about Symfony Security system before starting EasyAdmin course because we're talking about it there supposing you're already familiar with it.
Cheers!
Hi
I notice that Easy Admin has been updated since you did this tutorial, there is now no html.twig files and therefore no start point for creating the admin page which quite frankly makes it very difficult to proceed as it offers you 3 options that at this time mean very little therefore making it impossible to proceed further. Can you make this available for the tutorial please as it really confuses the whole start process.
Cheers
Rob
EasyAdmin 4 requires PHP 8.0.2 or higher and Symfony 5.4 or higher. Why did you say that it only for Symfony 6?
Hey Andrzej S.
I'm afraid there was a confusion. This tutorial uses Symfony 6 and PHP 8 but it doesn't mean that you can only run EasyAdmin on those versions. EasyAdmin comes with its own version constraints that you can check here https://github.com/EasyCorp...
I hope I managed to clarify the situation. Cheers!
Thanks for the reply, it's helpful.
By the way, I love your tutorials and I learned a lot from them.
Hi there,
I tried
docker-compose up -das in readme and I got the errorERROR: Version mismatch: file ./docker-compose.yaml specifies version 3.7 but extension file ./docker-compose.override.yml uses version 3.0Fixed the
docker-composer.override.ymland it workedHey Rodrigo!
Sorry about that! It was fixed in https://github.com/SymfonyC... - thanks for head ups!
Cheers!
Hey @Balduin
That's odd. I just downloaded the course code and the
README.mdfile is there. Could you download it again?Cheers!
Done
Do i need yarn .. or can i use EasyAdmin instead with the new AssetMapper .. ?
Hey Rufnex,
You don't need to have Yarn because all EasyAdmin assets are precompiled and work out-of-the-box. For your personal assets - sure, you can use that new AssetMapper. I suppose you would need to include your files as plain JS / CSS files instead of Webpack entries then.
Cheers!
I played a bit and it worked. Thank you.
Hey Rufnex,
Cool, thanks for confirming it works :)
Cheers!
I'm very confused, i downloaded the project files, and the migration file is intended for mysql
while the docker-compose file configures a postgresql container:
Should we use mysql or postgresql, or am i missing something?
Hey @ling
We are sorry for the inconvenience. Yeah, we are using MySQL server for this course, and this
docker-compose.yamlis the default part of the Doctrine recipe which was installed.I registered your issue in our internal issue tracker and we will improve it.
Thank you for the reporting! Cheers and happy coding!
I have an issue on installing the project.
When I run
composer install, I get this error:Any idea?
Thanks a lot since I have tried many things but with no success.
Hi @Nicolas-M,
We are sorry that you got this issue... As a fast solution install project with
composer update laminas/laminas-codecommand. It should work with PHP 8.2.Cheers and happy codding!
Thanks Sadikoff,
I started again from scratch, and ran these commands in this order:
But when I run:
I still get a blocking error which is mainly:
Hereafter is the complete return:
Any idea, please?
Hi Sadikoff,
Finally, I downgraded the PHP version from 8.2 to 8.0.25.
And everything is back to normal.
Cheers,
Nicolas
Hey, sorry that I was not able to answer previous message, but yeah, sometimes it's better to use PHP version course was designed, it's pretty difficult to support all PHP versions, but I will re-check this course compatibility.
Thanks for you report!
No problem - I learned a lot from digging everywhere. :-)
What am I doing wrong? Nothing is working..
Hey @excentrist!
Sorry about the trouble! I believe this is caused by Symfony now shipping recipes with Postgres version 14 and your local machine probably already have a Docker instance using Postgres 13. I have some more info and the solution here - please let me know if it helps!
https://symfonycasts.com/screencast/symfony-doctrine/docker-compose#comment-28388
Cheers!
Sorry, where's the solution exactly? lol
Oh geez 🤦 - https://symfonycasts.com/screencast/symfony-doctrine/docker-compose#comment-28388 - here it is (also added to my original comment above). Sorry about that!
Hi, first of all thanks a million for your awesome tutorials, truly love them.
I'm running into a bit of an issue during install here and would appreciate some help.
I've just downloaded the start archive & followed the install steps (without Docker), I'm currently using PHP 8.1.4. I've tried switching back to 8.0.12 & 8.1.2 (I'm using Laragon + manually updating Windows env vars) but the same error occurs.
However whenever I launch the Symfony server, I get the following error & unfortunately I'm unable to reach http://127.0.0.1:8000 - it never loads.
<blockquote>|CRITICA| REQUES Uncaught PHP Exception Twig\Error\RuntimeError: "An exception has been thrown during the rendering of a template ("Class "App\Entity\Category" does not exist")." at C:\Users\estel\Desktop\Symfony\SymfonyCasts\code-easyadminbundle\start\templates\base.html.twig line 18</blockquote>
When I go to base.html.twig :
{{ is_granted('ROLE_PREVIOUS_ADMIN') ? 'style="background-color: red !important"' }}I've tried closing & reopening VSCode, symfony server:stop & symfony serve again, but to no avail. Any help appreciated :) TIA
Hey Estelle G.
That's a very odd error because the entity
Categorydoes not exist in this project. Did you change something after downloading the start directory?Try clearing your cache
rm -rf var/cacheand reinstall your vendorsrm -rf vendor && composer installOh, and if you're on Windows, try using "localhost" instead of "127.0.0.1"
Cheers!
Thanks for your reply. Well I am not sure what happened, possibly some sort of witchcraft ahah but well anyway after restarting my PC & this project today it now works perfectly fine, but thank you anyway :)
Hallo, May i ask a question please?
I got missing translation messages in easyadmin 4
`
# symfony console debug:translation en --only-missing
State Domain Id Message Preview (en) Fallback Message Preview (de)
missing time diff.empty diff.empty diff.empty
missing EasyAdminBundle label.form.empty_value label.form.empty_value label.form.empty_value
`
I tried in app/translation/messages.en.yaml:
<br />label:<br />---- form:<br />-------- empty_value : abc<br />but still got missing, how can i fix this thanks
in vendor/easycorp/easyadmin-bundle/src/Resources/translations/EasyAdminBundle.de.php
->i found 'label' => 'form.emtyp_value' => 'keine Wert'
...
Hey Luong,
Hm, sounds like a type in the message key, right? Good catch! It's a great opportunity to create a PR to the EasyAdminBundle. Are you going to do this?
Cheers!
Hi @victor yes i try work around with symfony and easyadmin, is great :). But i dont know why i still got missing messager ?_? how can overrider translation von easyadmin in 'de' order fix this missing
Hey Luong,
Here's the link to the docs that shows how to override translations from third-party bundles: https://symfony.com/doc/cur... . But if there's a typo - it's better to send a PR and fix it upstream in the bundle's repo. Then, just upgrade to a new release that will contains those changes.
I hope this helps!
Cheers!
Bonjour! May I ask a question please?
I should use CAS bundle for my app because we use SSO system. So, can i use the following bundle while I use Symfony 6 because there is no CAS bundle for Symfony6:
https://github.com/ecphp/ca...
I really appreciate your support and your hard work! ^^
Hey Lubna,
Unfortunately, I've never worked with CAS protocol before, so don't use those bundles myself. But let me give you some hints. First of all, I see that the bundle you linked https://github.com/ecphp/ca... does not support Symfony 6 yet, though there's an issue about it: https://github.com/ecphp/ca... - feel free to follow it to know when that issue is closed. Also, if you have time - feel free to help with upgrading that bundle and make it compatible with Symfony 6 and send a PR - that may have a good side effect, because even if the bundle is slow on reviewing/merging your PR - you will be able to use *your* fork in your project while PR is not merged yet.
Other options - you may want to take a look at GitHub search: https://github.com/search?o... - probably you will find that is still maintained. If no luck - you may want to use low-level tools that are used in those bundles to write the implementation yourself - take a look at composer.json file to see what libs are used behind the scene in those bundles that might help you.
Or, another option - downgrade your project to Symfony 5.4. Basically, Symfony 5.4 == 6.0, but in Symfony 6.0 just dropped all the legacy code since 5.x version. Though, it might work and you will be able to install that bundle, but keep in mind that if the bundle is dead and nobody will add Symfony 6 support there - you won't be able to upgrade to the newer version at some point.
I hope this helps!
Cheers!
Many thanks for your helpful response! All is clear.
Hey Lubna,
Glad to hear it was helpful for you! And sorry that I can't help more with this problem
Cheers!
Hi again!
After downgrading my app I have a problem in my auth. Could you plz take a look at my error message as below:
An exception has been thrown during the rendering of a template ("Unable to find the current firewall LogoutListener, please provide the provider key manually.").
So, I had to add a logout path under the firewalls in my security.yaml file. Right now I can login but can't logout. Please note that I use sso auth.
Have you any idea about that?
Many thanks in advance and have a nice day!
Hey Lubna,
Please, take a look at the config/packages/security.yaml configuration, in particular, at the "logout" key there. Most probably you need to specify path key manually for logout option under your firewall there.
If you do so, and don't see that error anymore - great, but what error do you see now? What happens where you logging out?
Cheers!
Thanks for your reply! after clicking on logout nothing happens at all. I am still connected
Hey Lubna,
Well, still something should happen :) Were you followed the /logout path in the address bar of your browser? Were you redirected somewhere then? Could you show your logout configuration in your security.yaml? Also, your logout() route you created? Does it have something "throw new \Exception('This should never be reached')" inside or something like this?
Cheers!
Hey! thanks again.
yep I can find the redirected path while chlicking (mypath/logout) and see it in the address bar. Also, I added the logout route in my defult controller.
Hey Lubna,
Hm, ok... do you have a logout entry point like this?
Also, could you show your security firewall configuration?
Cheers!
Thanks again! I have the following route in my main controller:
And here is my firewall config:
Hey Lubna,
Thanks for sharing more details! Hm, your config looks ok, but let's try to tweak it a bit... Could you try to rename your firewall name "l3_firewall" -> "main" in this config? Also, make sure you renamed "l3_firewall" with "main" in other parts of your application if you're referencing to it somewhere. Then, (and it's important steps next!), clear the cache, next reload your fixtures that should force logging out the current user, and finally log in again and try to logout. Still can't logout?
Cheers!
"Houston: no signs of life"
Start the conversation!