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!
39.
Linking to EasyAdmin from Twig
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
This is deprecated and will be removed in EasyAdmin 5. Routes are now normal and not ugly, and use the Symfony router.
Hey Tac,
Indeed, thanks for mentioning it!
Cheers!
that was easy but how I can do it with delete action ?
Hey mysiar,
IIRC delete action requires the request to be sent via POST method. So, you still generate the link the same way, but generate it for the delete action. And then use the generated URL in the
<form action="...">. I.e. you would need to send a POST request to that URL using form... or you can do it via AJAX call, but for this you would need to write some custom JS code. You can look at the delete contoller to see the logic how it works and what data need to send so that it works.Another alternative solution would be to write a custom method that will delete something "your way" and then return a result you need - probably the simplest (most flexible) one, depends on your task.
I hope this helps!
Cheers!
We should definitely simplify the use of ea_url in twig. This is powerfull tool, but mainly used in one way.
Hey Kslosarz,
Any alternatives for building URLs to EA in Twig templates? :)
What do you mean?
Cheers!
Yes, as of EasyAdmin 4.14 you can use the Symfony router: https://dev.to/javiereguiluz/new-in-easyadmin-pretty-urls-2knk
Hey Tac,
Ah, I got it. That's really good news. Unfortunately, this feature was not available when this course was recorded. Since it's an admin interface, that's not a big deal with URLs usually, but sometimes using pretty URLs is easier for sharing with someone.
Cheers!
Indeed, but sometimes you add a callout to indicate new info after the course was published.
It's not just a matter of getting rid of the ugly urls, but rather verbose way to generate a link using the ea_ twig function. By using the built-in router, you even get auto-complete. As javier mentioned in the post, it's been one of the most requested features, I'm guessing for the DX in twig than the urls themselves (though big bonus, tests are also much cleaner.)
Yeah, I remember people are requesting it a lot, but I thought that would never happen fairly speaking. Definitely a lot of benefits from pretty URLs, and that's great to see finally, Javier did a great job on it :)
Cheers!
"Houston: no signs of life"
Start the conversation!