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!
22.
The Dashboard Page
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
}
}
33 Comments
Hi. I have the error “Couldn’t find a package.json file in ProyectName” when I run the command “yarn watch”. I don’t have any errors in the console, and the canvas renders in the source code, but nothing is visible. What happened?
The file package.json no exists
Hey Marco,
Yeah, that error makes sense if you don't have package.json. Please, download the course code again - you will find the package.json file there, probably you accidentally removed that file (or moved it to a subfolder) in your project. With that file
yarn watchshould work well.Cheers!
Thanks, that works. But The chart dont render. In the html there is the code
<canvas data-controller="symfony--ux-chartjs--chart" data-symfony--ux-chartjs--chart-view-value= ... etc ... </canvas>There arent errors on browser or symfony.
Im using the same version of ux-chartjs (2.0) and webpack-encore-bundle (1.7) as in the course.
What Im missing to do?
Hey Marco,
Difficult to say without seeing the errors, it might be so that your NodeJS version is too fresh, take a look at the errors. Also, did you run all the required steps from the README.md file in your project? Probably you missed installing some dependencies, I would recommend you to drop the node_modules/ dir completely and reinstall the JS deps again.
I hope that helps!
Cheers!
Hi. Its a existing project, after the command "yarn watch" I had the error "error Couldn't find a package.json file in /"
How can I create the package.json?
Hey Marco,
That makes sense then :) We have symfony/webpack-encore-bundle package installed in this course, if you will install it - the Symfony Flex will execute a recipe that creates that file for you with some pre-installed dependencies. If you don't need that - you can create it yourself, just install any JS package you want with for example Yarn.
Cheers!
hi @weaverryan,
Firstly, let me thank you for the excellent tutorials - i have bought access to couple of them and all of them are really helpful.
I need your advice.
I have an entity with two association fields. thanks to your video, I have configured the fields in a way that when i type, the easyadmin makes ajax calls and searches through the association fields. I need to restrict the second field search using value of the first field.
What is the best strategy to achieve that?
Hey @curiousDA!
Thanks for the nice words!
Hmm. That's an interesting question! The underlying challenge is that, when you use the
AssociationFieldwithautocomplete, when the Ajax request is made to fetch the options for a field, the only data that is sent on that Ajax request is what the user typed into the field. So, for example, if you have a field calledCountryand a field calledCity, when the user types intoCityand the AJAX request is made to fetch the options forCity, the PHP code that fetches those options doesn't know what current value ofCountryis. And I can't really see a way around that :/. So this seems oddly difficult.The only workaround I can see would be to:
A) Write some custom JavaScript that listens to the
changeevent forCountry(to keep using my example).B) On that JavaScript listener, find the
Cityfield. Its element should have adata-ea-autocomplete-endpoint-urlattribute on it.C) Modify that attribute by adding / changing a
&country={value}onto the end of it.This should cause the AJAX request made to the
Cityautocomplete to have an extra&country=on the URL. Then:D) Override the autocomplete method in your controller and if the current field is
City, manually read thecountryquery parameter and modify the query.Also, make sure you have some validation on your final object that validates that the final value for
Cityis ok for the selectedCountry(to prevent a bad user from sending bad data).So, I think this might be possible - but it's annoyingly difficult! Let me know how it goes if you try it.
Cheers!
Hi team,
I'm trying to create a menuItem::linktoCrud with parameter for an Index Page. In a classic controller you can do that easily and get it in the route. I try it with a linkToUrl and it's works fine. However I don't know how to do that in EA. Have you got a solution? How to add a parameter in the url, the same as setEntityId() (or to disabled test when loading setEntity()... CrudMenuItem is a final class so I can't override it (I'm not sure because it's hard for me). Thak's for help
Hey @Delenclos-A
You'll need to use the
AdminUrlGeneratorservice https://symfony.com/bundles/EasyAdminBundle/current/crud.html#generating-admin-urlsIt has a
setRoute()method that allows you te define the route name and parameters, then, you get back the final URL, you need to callgenerateUrl()I hope it helps. Cheers!
I have followed all the steps, upgraded everything, and I am not able to see any chart. There are no errors displayed in the console or the development panel. I have executed commands like
yarn install --forceandyarn watch, but the chart still doesn't appear. Has anyone successfully run it recently with the current library versions?The environment I'm using is as follows: PHP 8.1.13, Symfony 6.0.2, Google Chrome, and Mac OS X.
Hey Marek-J,
Did you download the course code and start following the course from the start/ directory? Did you run
composer updatecommand or onlycomposer install?Could you try to clear the cache also with
rm -rf var/cache/just in case? Also, try to open the page in Chrome Incognito mode, it might still be browser cache, though force refresh should do the trick I think.Cheers!
I downloaded Start/ at the beginning of the course and followed the coding instructions up until this chapter. Now I run 'composer udpate', rm -rf var/cache, repeated yarn install --force and yarn watch, forced cleard cache, opened chrome in icognito mode, but it still doesn't work without any error.
I checked source code and I have chart code, but I'cant see it.
Hey Marek-J,
Ah, we do not recommend to run
composer updatecommand while following the course because it may lead to some unexpected BC breaks. If it possible - I'd recommend you to revert changes thatcomposer updatedid and just docomposer installorcomposer requireif it's shown in the videos. This guarantee that you will have the exact code that the course author has in the video.It's difficult to say what changes you need to do after you upgraded your project to newer versions.
Cheers!
Hi, I read all the tutorial and it's very hard for me (english and EasyAdmin). I have worked with SF2 (in the past). I appreciate tutorials because you go on detal and it makes sense to develop comprehension.
Imagine many admins who,works in one or many countries.
So they have to manage only their countries custommers, products...
I imagine that all is starting in the Dashboard. A query is generate to get all the entities we need in the cruds and only for the connected adminUser country.
I don't know how to do that. If someone can help me I appreciate. Thank's
Hey @Delenclos-A ,
Actually, not really in the Dashboard :) I suppose you want the Dashboard will look the same for all your customers, i.e. same links to the users list page, etc. But when you click on that Users link - you will see only users related to your country. So, this could be done by overriding the index page query builder in your
UsersCrudController, i.e. specificallycreateIndexQueryBuilder()method - you can add any special conditions to the query to filter the list of users returned. But you would probably want to add some extra checks to avoid guessing the user URL in the address bar, otherwise some admins may open not their own users by going directly to the user id page, i.e. changing entity_id query parameter in the addres bar :)Actually, I would recommend you to watch this tutorial till the end, we're talking about restricting access to some users in it :)
Cheers!
For me nether the simulus app for the text-field-preview from the lesson before or the chart is working. No error in the console, nothing.
Tried several package-updates or copying the original code from the zip-file. must be missing something here. node v16, npm v8.18 and yarn v 1.21
not that important to me. more a nice-to-have.
Hey @Ek24!
Well that is no fun! Hmm. Here are some things to check:
A) First, do you see the data-controller="" attribute in the HTML on the rendered page? This is kind of obvious.... we just want to make sure that the data-controller IS actually rendering.
B) If data-controller IS rendering, then it means that the corresponding Stimulus controllers are missing for some reasons. If the Stimulus controllers were registered, then they would at least load and then have an error. Not seeing anything means that either the data-controller="" is missing, the Stimulus controller is missing, or there is a naming mismatch between them. But the chart controller name is all handled pretty automatically, so I doubt that it's a name mismatch.
So... my guess is that the problem is (B) that, somehow, the Stimulus controllers are missing. I'm not really sure how that could happen - but I would "back up" and try creating a really simple
assets/controllers/hello_controller.jswith:Then, on a non-admin page, add
<div data-controller="hello">onto the page. When you refresh, do you see the text above added to the element? We're testing to see if the Stimulus controllers are working at all.Oh, ALSO make sure you're including the Encore assets in your admin area - https://symfonycasts.com/screencast/easyadminbundle/assets#codeblock-9cb529831f - in that case, we created a new "admin" entry to hold the admin stuff (but use
addEntry()notaddStyleEntry()as you'll also be including JavaScript... and pointaddEntry()atadmin.jslike we do here https://symfonycasts.com/screencast/easyadminbundle/field-javascript#codeblock-0353f83ac2). To make sure Stimulus is loading, that file needs to import the./bootstrapfile - we show that later - https://symfonycasts.com/screencast/easyadminbundle/field-javascript#codeblock-b7c4c00273Let me know if that helps! Cheers!
Hello, so for anyone having the same issue, like I was, this was the answer that helped me. If you want the easy steps to follow, here is what I did (I am using Symfony 6.2.6, PHP 8.2.3, Node v19.7.0 and NPM 9.6.0) :
assetsdirectory (name it however you want, here let's say it's dashboard.js)import './bootstrap';webpack.config.jsfile and add this entry :.addEntry('dashboard', './assets/dashboard.js')src/Admin/DashboardController.php:(Don't forget to import
Assets)symfony serve&npm run watchHi @Faez-B!
Thanks for posting that! I can't remember why I didn't need to do this in the actual tutorial, but this is sound advice. The point is: somehow, you need to make sure the Stimulus engine is running. Creating an admin-specific entry (that imports
'./bootstrap') like you suggest is a completely valid way to do that. The other way would be to make sure your normalappentrypoint is included in your admin area, though this could also introduce extra styling from your frontend that you don't want.Anyways - good stuff, thanks for sharing this 👍!
Hi, I have problem with displaying chart (I use Mac, Safari) I can see that render is complete
But I can not see the result, try yarn install --force and after yarn watch, no result. In console no errors...
What I do wrong ?
Hey Mepcuk!
Sorry for the slow reply! Hmm. When absolutely nothing happens (including no errors), it "feels" like the Stimulus controller isn't been registered. What does your
controllers.jsonfile look like? Alsopackage.json? Something is short-circuiting I think... but I'm not sure what. Also, if you have the latest of all of the js packages (e.g. runyarn upgradeornpm update), then you should see some console logs from Stimulus itself. It'll say something about Stimulus "starting" and then tell you about any controllers that are starting. Even if the controller is missing, if Stimulus is running, you should see some logs from Stimulus about IT booting up.Let me know what you find out :).
Cheers!
Solved - S6 Php8.1 - need to restart local web server (symfony serve) - any commands like yarn watch and other not help me.
Hey Maxim,
Thank you for sharing this tip with others! I'm happy to hear it fixed the problem for you
Cheers!
Do you know why I'm not getting autocompletion for path() within the admin twig templates in phpstorm anymore and how to fix it?
Unfortunately, I don't know how to fix it :/. That's... surprising that you've lost auto-complete... and I'd definitely check that the Symfony plugin is enabled for the project. But sometimes, autocompletion in Twig gets a bit inconsistent (it's usually inconsistent with what variables it autocompletes... which makes sense, since it's tricky to figure out which controller is rendering the template... to know which variables it's providing), but I don't have as many problems with actual Twig function, like path().
Cheers!
oh, the path() function itself autocompletes, but none of the route names are autocompleting within the call to path.
Actually that's not true, only the paths in the Controller/Admin directory controllers as well as web profiler paths; but none of the paths in the controllers in the Controllers directory like "app_profiler_show" and "app_homepage". The symfony plugin is enabled
Ah yes, this happens to me sometimes too... but I'm not sure why. This magic comes from the Symfony plugin... so something isn't quite right there, but I don't know how you'd go about fixing or debugging that :/.
Many thanks! Could you please share with us the way you have created findLatest() or topVoted() methods please?
Hey Lubna
There it is:
By the way, you can find them inside the
QuestionRepository.phpfile.Cheers!
Dear all, thanks for all those great courses. I have a doubt: I can set different controllers for the same entity (alternate detail pages), but can I set a common url for the actions?
Hey @Luc!
Hmm. It sounds like you want to, for example, "share" (for example) the "edit" action (or some other action) between two Crud controllers for the same entity? If so, I do not believe this is possible: the controllers operate completely separately. However, if you have custom logic inside of one of the actions that you want to share, you could certainly add that custom logic to one of your Crud controllers and make the other *extend* that controller to share the logic.
Let me know if that helps :).
Cheers!
"Houston: no signs of life"
Start the conversation!