Chapters
21 Chapters
|
2:23:48
|
Login to bookmark this video
-
Course Code
Login or register to download the code!
Login or register to download the code!
-
This Video
Login or register to download the video!
Login or register to download the video!
-
Subtitles
Login or register to download the subtitles!
Login or register to download the subtitles!
-
Course Script
Login or register to download the script!
Login or register to download the script!
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!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/asset": "6.0.*", // v6.0.3
"symfony/console": "6.0.*", // v6.0.3
"symfony/dotenv": "6.0.*", // v6.0.3
"symfony/flex": "^2", // v2.4.5
"symfony/framework-bundle": "6.0.*", // v6.0.4
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.4.3", // v6.4.3
"symfony/twig-bundle": "6.0.*", // v6.0.3
"symfony/ux-turbo": "^2.0", // v2.0.1
"symfony/webpack-encore-bundle": "^1.13", // v1.13.2
"symfony/yaml": "6.0.*", // v6.0.3
"twig/extra-bundle": "^2.12|^3.0", // v3.3.8
"twig/twig": "^2.12|^3.0" // v3.3.8
},
"require-dev": {
"symfony/debug-bundle": "6.0.*", // v6.0.3
"symfony/stopwatch": "6.0.*", // v6.0.3
"symfony/web-profiler-bundle": "6.0.*" // v6.0.3
}
}
37 Comments
I followed the steps and cannot access to the route, just a 404 error was thrown.
The solution was as this post https://stackoverflow.com/a/73933837
I cannot found any of that requirement in tutorial or documentation. I am wrong?
Hi AlejandroVillafane!
Hmm, that is super weird! So, no, you should not need to do anything like what's described in the StackOverflow post: it should work out-of-the-box. But let me explain, so we can maybe find the problem :).
When you start a new project (e.g. with
symfony new my_new_project), one of the files that you should immediately have isconfig/routes.yaml, which looks like this:THAT is what will load the "attributes" routes from your
src/Controllerdirectory. It looks slightly different than what's in the SO post, but it's effectively the same. So that poster IS right that you DO need a file like this... but it should be there without you doing anything :).Do you have this
config/routes.yamlfile in your app? If so, what does it look like?Cheers!
Thanks weaverryan
Yes, the file
config/routes.ymlexists.But the content is different:
That's the file content given with the project, without being modified.
Hi Alejandro!
Hmm, super weird. Are you starting a new Symfony 5.4 project? Basically, since Symfony 6.0, if you're starting a new app, your file should look like mine. But for 5.4 and earlier, the file would look like your version.
Cheers!
Hello , i did all the coding that i was instructed on this tutorial.
The problem is that when i refresh the page , the Welcome to
Symfony 5.4.24 page is still shown.
Hey @Michael-Kost
I'm guessing your routes are not being loaded for some reason, perhaps because you forgot to update the
config/routes.yamlfile. If you executephp symfony console debug:routerwhat do you see? It should print all of your routesCheers!
I ran the following command
symfony console debug:router
and i got the following message:
Name Method Scheme Host Path
_preview_error ANY ANY ANY /_error/{code}.{_format}
yea, it means your routes are not being loaded. Double-check your
config/routes.yamlfile. If you're using PHP attributes you need to set thetypekey toattributeWhen i open the config/routes.yaml file, i get the following
#index:
path: /
#controller: App\Controller\DefaultController::index
Ok, since you're in Symfony 5.4 you'll need to install
doctrine/annotationsand, of course use annotations on your routes (unless you're on PHP 8). You can find more info here: https://symfony.com/doc/5.4/routing.htmlCheers!
ok apparently this is broken using annotations so stoping the use of symfony until you figure out how to use it yourselfs. I think that the problem with frameworks is just amplified here. You keep updating the code base and outdating everyones beautiful creations. I do realize that you have to keep up with newer versions of PHP that keep comming out but at least update your beginers tutorials so people new to this would be able to get past the basics and create.
Hey Andromeda,
We're sorry to hear you have trouble with following this course! Could you share more information about your problem? Do you have problems with annotations? Do you see any errors? What errors exactly? Please, give us a bit more context and our support team will help you to fix it and move forward. Also important to know, did you download the course code and run the project from the start/ dir? Did you follow all the instructions in the README.md file? Did you ever run
composer updatecommand in your project?About this specific course, we do have automated CI on it that tests course code on PHP 8.0 and 8.2 and it does not show any problems in this course. So your problem might be an edge case problem that isn't covered by our CI or it might depend on your specific setup. We definitely would like to know about it so we could make the course code even better.
Unfortunately, project maintenance is a required non-stop process. Along with framework development devs should upgrade their projects as well at least to support new PHP versions as you said.
Cheers!
No errors it just dosn't work there is some issue with symfony that is making the annotation routing not work I tried installing it with composer even and nothing it just doesn't work I suppose I could have fought it harder and more but I choose to give up it is way easier to program php than someone elses interpreation of what php should be. I then know what is going on and don't have to weave through miles of spaggettie and extreme bloatwear to find out what the issue is.
Hey @Andromeda,
The issue is that Symfony doesn't include annotation reader BTW it wasn't a part of symfony at all, it was part of Doctrine library so the easiest way to get annotations back is install
doctrine/annotationspackage but with version constraintuse:
also there might be required one more package:
sensio/framework-extra-bundleI hope we got the correct understanding of the issue you have, also I'd like to know why do you need the support of annotations? From my point of view it's not a perfect solution for metadata it also requires some additional code to work, I mean it's not the part of PHP itself so it may have performance downsides so that's why I'm asking!
Cheers!
Hi there,
This is something I have already mentioned but I still did not find the way to the have an autocompletion with the use. It does not work on my laptop.
https://www.dropbox.com/s/qwjm5qfldtq0jc5/AutoImport.png?dl=0
Hey Benoit,
Did you have Symfony plugin installed? Please, make sure you have it installed and configured, but first - try to upgrade your PhpStorm to the latest version. Then, after all installs and upgrades - make sure to restart the PhpStorm IDE. Then it should work I think :)
Cheers!
Hey there,
My apologies for any inconvenience you may have experienced, but just to corroborate, is this the tutorial you got problems with? I'm asking because this tutorial was built with Symfony 6 and PHP 8
You may need to run
composer require annotationsto get the routes to load.Hey Matthew,
Yes, but only if you're defining your routes with PHP annotations, but in a modern Symfony app, you'd be using PHP attributes
Cheers!
I have created a TopicController with
#[Route('/{topic}', name: 'topic.index', methods: ['GET'])]and then I created Photographer Controller with
#[Route('/photographers', name: 'photographer.index', method: ['GET'])]Now if I try /anytopic , this goes to topic controller, and /photographers also goes to topic controller.
How can I force /photographers controller to go to Photographer controller?
Hey Ariful,
Good question! But the legacy workaround is simple ;) You just need to change the order of your controllers, i.e. make that "photographer.index" controller going first, it will do the trick. Or, switch to yaml config instead of PHP Attributes for that exact controllers and place them in the correct order there.
Also, since Symfony 5.1 you can set the "priority" for routes, see the blog post with example: https://symfony.com/blog/ne... - so if you're on a newer version of Symfony - this will be the best option for you.
Cheers!
I'm not quite sure where to put this.
I am creating a project in SF6, I created a couple of entities, migrated, yada yada, all good and dandy.
now, some tables have relations, and once I submit a form be it for add or edit, I get this error.
it happens when I try to add anything with relationships, I get that the form doesnt send the walletProvider object as is, but I havent modified any of that code that was generated through the make:crud function in the console, any pointers?
Hey jlchafardet
Could you double check your entities relationship? It seems to me that you have a OneToMany instead of a having a ManyToOne or OneToOne. If that's not the case I'd have to see your entitie's metadata and possible the form as well.
Cheers!
it is ManyToOne :S
<blockquote>
Entity
<br />#[ORM\ManyToOne(targetEntity: WalletProvider::class, inversedBy: 'coins')]<br />#[ORM\JoinColumn(nullable: false)]<br />private $walletProvider;<br />FormType
`
$builder
<br />Controller<br />#[Route('/new', name: 'app_coin_new', methods: ['GET', 'POST'])]
public function new(Request $request, CoinRepository $coinRepository): Response
{
}
`
</blockquote>
Ok, try this in your form type
with multiple => false works, but that goes against everything I'm interested in having... I need it to allow me to select multiple providers.
I see.. then, you need to rethink the relationship of your entities. What you need is to have multiple WalletProvider objects inside your other entity (I believe its Coin). Or, you can create an intermediate entity that will hold the collection of WalletProvider per Coin record
The key here is that your Coin entity is holding a single reference of a WalletProvider object, but what you actually want is to hold a collection of them (OneToMany relationship)
so in this case, what I should do is "start" the relationship of "OneToMany" from walletProvider, or straight up go "ManyToMany" as many wallet providers can hold many coins??
Let me see if I can explain it better.
There are many coins, just as there are more than 1 WalletProviders(at least 2 at this time but could be more in the future)
there are also "Wallets", so each Wallet can hold many coins, but 1 wallet can only belong to 1 WalletProvider.
does that makes more sense?
and to complicate it more, the app manages "users"
so each user can have 1 or more wallet, and each coin can have an "amount" that is tied to both the wallet and the user.
user 1, wallet-from-walletProvider-1,
accepts: coin1 and coin2
coin 1 balance: 22
coin 2 balance: 5
Hey jlchafardet
Ok so, you'll need a ManyToMany relationship on your Coin - WalletProvider entities
Then, the Wallet entity will have a OneToMany to the Coin entity, and a OneToOne (or ManyToOne) to the WalletProvider entity
I hope it helps. Cheers!
will do my best :D hopefully works the way I want it to work.
I'll let you guys know.
Great! For your User relationship it's not that easy to tell because I don't know the use-cases of your application but just keep in mind that you can add an intermediate entity that work like thin wrapper between your relationships, it's quite useful for storing extra fields and for adding behavior to the entities.
The relationships are in theory fairly simple.
Wallet Provider (Binance, KuCoin for example, they offer exchance services for cryptocurrencies[it is not really that important as the app does nothing nor has anything to do with trades, trading or the likes, we want them just because we want to know who provides the eWallet for the users.) its just there for us to know who provides the eWallet service. Each Wallet Provider can have many wallets, and support many coins.
Wallet: the eWallet itself, where the User will receive their coins, each wallet can hold many coins. but belong to a single user, and each user can only register 1 wallet.
Coin: the cryptocurrency our app will manage (we have 2, but might add more in the future), Users earn Coins for doing stuff, sometimes is Coin 1, sometimes is Coin 2, and in the future we might add Coin X.
User: the user itself, email, name, last name, favorite food, name of pet, foot size...... you get the gist of it. Each user can have ONLY 1 wallet, but can receive more than 1 coin to their Wallet.
this is the "MVP" aspect of the app.
I also have a role in user, that is not in use yet, but in a future iteration I want to be able to assign "regular users" to "staff users" to manage. example, we have 100 regular users and 3 staff users, Staff user 1, manages user 1 to 33, Staff user 2 manages user 34 to 67, and staff user 3 manages users 68 to 100.
in that iteration I will want to display in those "staff user" dashboard, a list of their "managed accounts". so they can only see what they should see. but we can get to that later :D.
did this get you a little better picture of what I want to do with the relationships? (another thing important to note is, the app itself does nothing more than parse a bunch of logs that cli tools output, and displays them on screen)
Hi,
I'm following the 'Symfony 6' course on SymfonyCast.
I run the commands:
I display the symfony initial page : https://127.0.0.1:8000/
I create the 'VinylController.php' file and the route #[Route('/')] via php attribute.
I refresh the page on my browser
and I get the following error.:
`Cannot rename
"C:\Symfony\mixed_vinyl\var\cache\dev\Container35B09qN\get93B0.tmp" to
"C:\Symfony\mixed_vinyl/var/cache/dev/Container35B09qN/get_Console_Command_ConfigDebug_LazyService.php":
rename(C:\Symfony\mixed_vinyl\var\cache\dev\Container35B09qN\get93B0.tmp,C:\Symfony\mixed_vinyl/var/cache/dev/Container35B09qN/get_Console_Command_ConfigDebug_LazyService.php):
Accès refusé (code: 5)
`cache:clear
gives the same error.<br />I have to remove thecache/dev` directory to continueIf i add the second method with a second route and i refresh the page
I get the same type of error again
Hey Michel,
Oh, this sounds like permissions error on Windows OS. You might need to double-check the permissions for that folder, but if you say that "rm -rf var/cache/" helps only until you edit a file and then the problem returns - most probably it won't help. I'd suggest you to put your project somewhere in a public dir, I see Symfony dir it's located in the root of disk C. Try to create a project somewhere in the user directory and try again, otherwise try to google this problem, most probably some Windows users may give you some hints over the internet.
Also, it might depends on how you run the PHP. If you're using a separate server like XAMPP, I'd recommend you to try to run it without admin permissions, or the reverse if you run it without admin permissions - it might help. Or probably better to install PHP natively in your system and use it directly with Symfony CLI built-in web server.
If no luck, I'd recommend you to take a look at Docker or other virtualization tools. Or probably better take a look at Windows WSL - Windows guys say that it's the best way lately if you're on Windows OS.
I hope this helps!
Cheers!
It seems that the Acronis anti-ransomware app is the cause of this issue
Thanks.
Hey Michel,
Ah, yes, some antiviruses might cause such errors too, good catch!
Cheers!
"Houston: no signs of life"
Start the conversation!