Chapters
40 Chapters
|
4:19:16
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
03.
Hello CRUD Controller
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
This tutorial is built on Symfony 6 but works great on Symfony 7!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2.0",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99.4
"doctrine/doctrine-bundle": "^2.1", // 2.5.5
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.2.1
"doctrine/orm": "^2.7", // 2.10.4
"easycorp/easyadmin-bundle": "^4.0", // v4.0.2
"handcraftedinthealps/goodby-csv": "^1.4", // 1.4.0
"knplabs/knp-markdown-bundle": "dev-symfony6", // dev-symfony6
"knplabs/knp-time-bundle": "^1.11", // 1.17.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.5
"stof/doctrine-extensions-bundle": "^1.4", // v1.7.0
"symfony/asset": "6.0.*", // v6.0.1
"symfony/console": "6.0.*", // v6.0.2
"symfony/dotenv": "6.0.*", // v6.0.2
"symfony/flex": "^2.0.0", // v2.4.5
"symfony/framework-bundle": "6.0.*", // v6.0.2
"symfony/mime": "6.0.*", // v6.0.2
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.0.*", // v6.0.0
"symfony/security-bundle": "6.0.*", // v6.0.2
"symfony/stopwatch": "6.0.*", // v6.0.0
"symfony/twig-bundle": "6.0.*", // v6.0.1
"symfony/ux-chartjs": "^2.0", // v2.0.1
"symfony/webpack-encore-bundle": "^1.7", // v1.13.2
"symfony/yaml": "6.0.*", // v6.0.2
"twig/extra-bundle": "^2.12|^3.0", // v3.3.7
"twig/twig": "^2.12|^3.0" // v3.3.7
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.1
"symfony/debug-bundle": "6.0.*", // v6.0.2
"symfony/maker-bundle": "^1.15", // v1.36.4
"symfony/var-dumper": "6.0.*", // v6.0.2
"symfony/web-profiler-bundle": "6.0.*", // v6.0.2
"zenstruck/foundry": "^1.1" // v1.16.0
}
}
25 Comments
Hey Nicolas,
We're sorry for this! Yeah, EA changed some styles lately, and you need to do some extra steps to see that side menu. Please, follow the instructions in the previous chapters, you can find them in the note: https://symfonycasts.com/sc... - look for "Since version 4.0.3 of EasyAdmin" text there.
I hope this helps! If not - let us know!
Cheers!
Hello,
I had a errors in this chapter with linkToCrud (and more errors with routes) and could not figure out what is going on.
Until I notice admin links are pretty links and are different from this video.
I got into reading Symfony Documents and found -"The support for pretty admin URLs was introduced in EasyAdmin 4.14.0" and
enabled by Default!
I try to disable them and it worked but not all still more error popped out. It was not possible to follow this tutorial. I got stuck . Version 4.14.5 isn't compatible. (took me two long evenings to figure this out :)
Solution: to save time and get hands on Tutorial is to start from beginning and this time install admin 4.0.2 with command below:
Hey @OjarsBluzma
Thank you for informing us. We'll look into it
Cheers!
Hello,
I don't know why but every time I click on the linktocrud tabs in my menu, nothing happens, I have nothing displayed but I have data in my database, I don't understand why it show nothing
Can you help me, thank you
Hey Dahrag,
I suppose you have some code inside
configureMenuItems()but nothing is shown in the browser? First of all, you can put add()statement inside the method to make sure application hit that spot. Probably you just forgot to extend a base controller (AbstractDashboardController)? Also, make sure youyieldthatMenuItem::linkToCrud()otherwise it will do nothing, because you need to return an array of menu items from that method :)And just in case, clear the cache and try again :)
Cheers!
I have a general question.
Assume that I have several Sub Admins users that have a oneToMany relation to their set of users, i.e., the users they are responsible for.
I would like to know if it is possible to list in the crud controller only the users that own the current sub admin user, because the sub admin should not be able to manage users that are not related to him.
Is this possible, and how?
TIA
François
Hey Francois,
Yes, it should be possible with some more custom work, not something that may work out of the box. I believe you need to override base
createIndexQueryBuilder()method in your EA CRUD controller, it will allow you to add any additional conditions to the query that lists entities. Also, you may want to override more methods. likedetail(),edit(),delete()to add some custom logic that will help to determine if the current admin has access to the entity if needed, because you know, you can hack the URL and still open an entity that is not listed on index page, so depends on how secure you want to handle it.Cheers!
I saw the tip in the last video, and added the admin/index.html.twig file, and I DO get a menu bar on the left.
But when I add "yield MenuItem::linkToCrud('Questions', 'fa fa-question-circle', Question::class);"
It causes: "An exception has been thrown during the rendering of a template ("Unable to find the controller related to the "App\Controller\Admin\Question" Entity; did you forget to extend "EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController"?")."
Edit: Nevermind, I forgot the use statement for App\Entity\Question; I'm pretty new to OOP, so I recently learned that static methods don't need the use statement, but Question::class is not actually a static method, ... so you still need the use statement. My bad.
Hey @Ryan-L
It's great that you could fix your problem. Regarding "use statements" you need them when the file is on a different namespace, whether or not is a static call
You don't need to add the use statement if you're using the FQNS e.g.
new App\Some\Service();Cheers!
Do I see it correctly that the CRUD system requires the SensioFrameworkExtraBundle. Is there an update planned to use Symfony internally?
Hey @Rufnex
Good catch, I believe something in this tutorial is still using annotations instead of PHP attributes, but if you're not using them in your project you can remove
SensioFrameworkExtraBundle. Also,EasyAdminBundleversion 4 does not force you to use it, but perhaps a lower version willCheers!
Hm, i get no navbar on the left .. i use the latest sf and easyadmin. i see only the welcome page. any ideas why?
if i use a custom template like that
And call it in index() with return $this->render('admin/my-dashboard.html.twig');
It works. Is this a normal behavior?
Hey Rufnex,
Hm, do you have
DashboardController? Do you have any menu items in theconfigureMenuItems()method of it?Could you share a screenshot maybe? You can upload to an image hosting like e.g. Imgur and send the link to it. Is there a chance that the menu was accidentally collapsed for you?
Cheers!
With return
parent::index();it doesnt work (only the splash welcome displays).Hey Rufnex,
Ah, yes... you've probably missed the previous video where we mention that in a newer version of EasyAdmin, see https://symfonycasts.com/screencast/easyadminbundle/dashboard#:~:text=the admin dashboard!-,Tip,-Since version 4.0.3 . So that's ok, just follow the instructions in that note to follow this tutorial :)
Cheers!
You're right . i missed it, but i found the solution by myself lol. Thank you ;o)
Hey Rufnex,
That's even better! 💪🏻 I'm happy you were able to find it yourself ;)
Cheers!
How Can I change the default welcome page. No matter the changes i've done, it always look the same and different from this one page.
Hey Marco,
Do you want to change the dashboard default page? If so, we are talking about it later in the course, see: https://symfonycasts.com/screencast/easyadminbundle/dashboard-page
I hope this helps!
Cheers!
Hi Symfonycasts Team.
Currently, the URLs look very cryptic for users.
If I would like to use EasyAdmin to provide this interface to customers or normal users, is there a possibility to display these URLs in a more user-friendly way? Possibly even in SEO form?
Hey Michael,
I'm afraid there's no easy way for this out of the box. I'm not saying that it's impossible, you probably may override some things in the source code, or even fork the EA, but it definitely won't be easy, because as you will see further, EasyAdmin put a lot of stuff in that URL, including sorting by column, search query, applied filters, etc. So, by design, it's not supposed to work with SEO urls by default, and it's an internal "admin" feature that's hidden from your users and search engine robots that will parse your website, so it's not that important. Though on the other side, I see what you mean, sometimes clients may want to see nicer URLs and it may be a problem with EasyAdmin.
Well, you can disable signed URLs for EA, and it will not include that long hash for "signature" query parameter in the URLs - it will help a bit, but will make URLs a bit more guessable and compact, but still other query parameters will still exist like Controller and action names at least.
Here's an issue that might be interested for you: https://github.com/EasyCorp... - you can see Javier's answer on it and the exact reasons why it's working this way.
Cheers!
Hello Victor.
Thanks for the quick reply.
The issue is indeed interesting (even if the attitude of javiereguiluz is rather averse :-D ). I was basically about - what you have already guessed correctly - that you could use the admin panel possibly also as a user area for customers or externals. And for this at least the mentioned adjustment of the URL in the issue would be better than the current state.
Let's hope that we get javiereguiluz convinced :-)
Hey Michael,
Yeah, I see what you mean. But that's not because Javier "hates" SEO URLs.. it's just about simplicity, this decision was made by design, and it's easier to maintain. So, I'm sure it won't be changes in the nearest future unfortunately. So, you either should take care of it yourself, but it might be pretty complex IMO, or just take a look at other solutions like SonataAdminBundle or ApiPlatform admin. I hope this helps.
Cheers!
Hey Nicolas,
Awesome! Thanks for confirming it works for you now :)
Cheers!
"Houston: no signs of life"
Start the conversation!