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!
37.
Custom Controller & Generating Admin URLs
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!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
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
}
}
10 Comments
The tutorial is amazing! Thanks for the great work!
Minor note: I completely failed to add a custom action button similar to the "approve" button in my project within the EDIT page. After submitting, the error was that no "ea" key was found. After some code digging and attempts like building the twig template for the action manually without the include (and to mimic the other buttons) I worked around the error but the approve-action never got fired. I finally gave up and switched to the DETAIL page like in the video. And voilà - it worked.
Yo! @Bernd
Thanks for the feedback! Yeah sometimes creating something custom in EA is a challenge and it's easy to get lost, however it's cool that you found a way to achieve what you need!
Cheers!
Trying to do that modal, but I'm stuck at the part how you can access current entity like displayIf does with a closure?
All idea's are welcome :)
Hey Rudi-T,
Yeah, that's tricky. It's not something that could be done easily, unfortunately. But there're some workarounds. If you're on the PAGE_DETAIL of a User, you can fetch the related User from
AdminContext, e.g:just add
dd($user)to debug that you get what you need at that point. You should be able to get thatAdminContextinstance by injecting theEasyCorp\Bundle\EasyAdminBundle\Context\AdminContextservice into your controller (or custom action). Or, in theory, it should be fetched from$this->getContext()call in the CRUD controller, but be aware that it may return null sometimes.I hope this helps :)
Cheers!
Nice tutorial so far! I love it and EasyAdmin :D
Is there an easy way to generate an Admin URL with a preset filter?
For example, if I want to create different submenu items under the "Question" menu item, to list only the questions related to each topic
Questions
- All
- Pending Approval
- Topic 1
- Topic 2
and on click should the question index action be called, but with a filter for the chosen topic.
Or is there maybe another way to sort of create a nested CrudController?
Hey Speedyschmid,
Thanks for your feedback! We're really happy to hear you love the tutorial, and moreover the EasyAdminBundle :)
About your question, there's no easy way for this. Well, first of all because menu item and filter are different concepts, though they might provide a similar result. But if you want to do some shortcuts for the filters - you can do it I think, just build the proper URL with corresponding query parameters. To know which query params to use - go to the index page and apply the filter you want, then, look closer to the URL - you would need to build the same query params for the submenu link.
And it should work this way, though it's still not perfect probably, because if you're referencing to topics by ID - it won't work on both: production and local. Because most probably you will have different IDs on production :) But you can try and see if it fits your needs.
I hope this helps!
Cheers!
Just wanted to reply myself, that I found a solution that works for my case - not with a preset filter, but a sort of nested Controller.
If anyone else is interested, here is how I do it:
`
$topics = $this->topicRepository->findAll();
$questionTopicSubItems = [];
foreach ($topics as $topic) {
$questionTopicSubItems[] =
}
`
Inside the QuestionCrudController inside createIndexQueryBuilder() i look for the query param and if exists, add the where condition
`
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
}
`
Hey Speedyschmid,
Good job finding the solution yourself! Well done! And thanks for sharing it with others ;)
Cheers!
Bravo! please keep going! my awaited tutorial is the next one! Can't wait to learn how to export data :)
Hey Lubna
Yo! Thanks for the feedback we will do our best!
Cheers!
"Houston: no signs of life"
Start the conversation!