15.
Fetch me a User Object!
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.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
8 Comments
hello, I encounter a problem in the method newAction, the part $ this-> getUser () -> getEmail (), the method getEmail () is not loaded. So I looked for why, I went to the file vendor / symfony / symfony / src / Symfony / Bundle / FrameworkBundle / Controller / Controller.php, but the latter is different, I did a composer update in git bash thinking that something was broken in symfony, but nothing works, I was also see a blank project where i install symfony and the file is identical, so I deduce that being at version 3.4 of symfony, the general configuration is different I do not know how to adapt this content for it to work. Could you help me please?
Hey teddy
Could you show me what does "$this->getUser()" returns to you? Or if you are getting any errors
I believe you are not getting the user object because you forgot to login in. but, well, let's check it out
Hive a nice day
What I like to do in my entities is to have a __toString() method. In this case it would return the email property.
You can then just call $this->getUser() in controller or app.user in twig.
If you add more properties to your User entity later, for example first name, last name etc. and want to show that instead of email, you dont have to edit all the files only toString method.
Hey edin
I like your approach, but I kind of see it like a personal preference, some guys may love it but some others may not like :)
Have a nice day!
Hi, which plugin takes care of the app.user auto completion in twig (at 3:00 in the video)?
Hey Webber,
All that magic are from Symfony Plugin, see more info about it in our PhpStorm screencasts which is free: https://knpuniversity.com/s...
Cheers!
I added an extra property to the Users table, call it "University" and I would like to use such property to filter certain rows in the formType when creating a new entry to the Aquanaut table. So far I have been able to do it on my listAction function but I can not seem to be able to do it in the createAction function.
Thank you very much in advance!
Hey Javier,
If you want to filter entities in form type - you need a query_builder option, check Using a Custom Query for the Entities. With it you can make a custom query for entity list and return filtered list.
Cheers!
"Houston: no signs of life"
Start the conversation!