Chapters
33 Chapters
|
3:34:13
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
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!
19.
Custom User Method
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.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.0
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.1.4
"symfony/cache": "^3.3|^4.0", // v4.1.4
"symfony/console": "^4.0", // v4.1.4
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.1.4
"symfony/lts": "^4@dev", // dev-master
"symfony/property-access": "^3.3|^4.0", // v4.1.4
"symfony/property-info": "^3.3|^4.0", // v4.1.4
"symfony/security-bundle": "^4.0", // v4.1.4
"symfony/serializer": "^3.3|^4.0", // v4.1.4
"symfony/twig-bundle": "^4.0", // v4.1.4
"symfony/web-server-bundle": "^4.0", // v4.1.4
"symfony/yaml": "^4.0", // v4.1.4
"twig/extensions": "^1.5" // v1.5.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.1.4
"symfony/dotenv": "^4.0", // v4.1.4
"symfony/maker-bundle": "^1.0", // v1.7.0
"symfony/monolog-bundle": "^3.0", // v3.3.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.1.4
"symfony/stopwatch": "^3.3|^4.0", // v4.1.4
"symfony/var-dumper": "^3.3|^4.0", // v4.1.4
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.1.4
}
}
19 Comments
Instead of
$uri .= sprintf('?size=%dx%d', $size, $size);you can do$uri .= sprintf('?size=%1$dx%1$d', $size);. This removes the duplication of the $size arguments.Thanks for sharing it!
You should not write your robohash-url in your entity, please use a view-helper instead, god damn it :-p
Hey Szabolcs!
That's definitely a valid way to handle it :). Because I don't need any service logic, I can use the simpler solution and put it in the entity. But it *is* true that if, later for some reason, we need to refactor this logic to require a service, we'll need to do more work (update our templates) to make that change. So better organization now would make that possible situation easier later.
Cheers!
public function getAvatarUrl(string $size = null)I think you meant
inthere, notstringYou're right! That's our fault. I'm gonna fix it right now :)
Thanks for letting us know!
{{ app.user.username }}
Where does .user come from? You might have explained it, but I can't remember. Is it coming from the User class?
Is it guessing wether .user matches the User class?
Hey Farry7,
It looks like you've missed some information following this course :). That "app" is a special global Twig variable, it's an object of AppVariable class, that has some useful methods, one of them is "getUser()". But Twig is smart enough to call getter methods behind the scene when you call just {{ app.user }}, i.e. behind the scene Twig will call that getUser method that will return the current logged in user or null. Basically, you can manually specify that method like {{ app.getUser() }}, but usually everybody shorts that call to just {{ app.user }{.
Hope this is clear for you now.
Cheers!
Ok, so what you can do is to check both configurations and look if something relevant is different. If you run
php -iin your terminal you will see all PHP settingsHey @disqus_uUZdE4XYyx
Does it work when you run your application through the browser? If you only got that error via a console command it's very likely that it's running a different php executable.
Cheers!
I don't know if this is a good idea or not, but I ended up passing the user to the view, in this way I've got both autocompletion in PHPStorm and a shorter way to get the user data:
In the view:
{{ user.firstName }}Hey Duilio P.
The only downside I see to your approach is that you could pass a different User object to your template and it would look like as the logged in user. About autocompletion, I have the same problem, I believe the Symfony plugin has a bug on it.
Cheers!
Thanks, you're right :) I'll remember to add a test for that or to use
app.userinstead.Well PHPStorm does autocomplete the app.user variable inside of twig, but it doesn't do it any further (it can't autocomplete/doesnt show anything beyond app.user.) is that normal?
It behaves exactly the same for me. I believe there is a way to tell PhpStorm the instance of which class is that varaible but I'm not sure how. Probably you can talk to the developers of the Symfony plugin about this.
Cheers!
By starting > v5, FontAwesome starting tag is "fab" but not "fa". :)
Please, fix it inside the html.twig files :)
https://fontawesome.com/ico...
Regards.
Hey Abelardo L.!
You're right! Well, we're using FontAwesome 4 in this tutorial - that's why we have the fa tag :). But if you're using Font Awesome 5, then you're totally right:
fab fa-twitter.Thanks!
In the getAvatarUrl method, why do you call `$this->getEmail()` instead of `$this->email`?
Hey Tom!
No particular reason. In general, I tend to like to *always* call my getters, in the (rare) event that I add some sort of logic in that method that changes the return value in some way I want, or maybe throws an exception if something isn't right. It just gives me that flexibility if I need it, which is honestly rare in these very simple entity classes. For me, both are fine :).
Cheers!
"Houston: no signs of life"
Start the conversation!