Linking to EasyAdmin from Twig
…I love it! We see the icons here... and if we go anywhere
else - like to an Answer's detail page - the icons are here too.
At this point, we know how to generate a link to any EasyAdminBundle page. If I
scroll up a…
Having Fun with the Menu
…but this time leave the
label blank. So unlike sub-menus, which wrap menu items, you can just pop
a section anywhere that you want a separator.
Let's go check it out. Refresh and... very nice! Separator one says "Content"...
and separator two gives…
Role Hierarchy
…a pain in the butt!
Fortunately, Symfony has a feature just for this called role hierarchy. Open up
config/packages/security.yaml and, anywhere inside of here... but I'll put
it near the top, add role_hierarchy. Below this, say ROLE_ADMIN and set…
Security Listener System & Csrf Protection
…a CSRF token... then,
on submit, you validate that token.
Let's do this. Anywhere inside your form, add an input type="hidden",
name="_csrf_token" - this name could be anything, but this is a standard name -
then value="{{ csrf_token() }}". Pass this the string…
When Authentication Fails
…to your users - you can do this.
Open up config/packages/security.yaml. And, anywhere under the root security
key, add a hide_user_not_found option set to false:
This tells Symfony to not convert UserNotFoundException to a BadCredentialsException.
If we refresh now... boom…
Testing with the "in-memory" Transport
…find it.
This... is basically a fake transport. When a message is sent to it, it doesn't
handle it or send it anywhere, it stores it in a property. If you were to use this
in a real project, the messages would then disappear…
Querying for One Pet
…is to make it accessible anywhere by moving that stuff to a
new function called get_connection. Let’s do that:
function get_connection()
{
}
With variables, you have to worry about scope and what you have access to.
But functions can be called from anywhere…
Centralized Configuration
…$configVars in config.php:
// lib/config.php
$configVars = array(
);
This change looks safe. I mean, it’s not like we’re using this variable
anywhere inside this file. But when we refresh, things explode! We are
referencing the old $config variable inside get_pets…
Debugging
…have an invalid path, which could be
an invalid logical path in a template or an invalid relative path in some
import somewhere.
By the way, there's an almost hidden way to see if any invalid imports appear
anywhere in your code. First, run:
…
configureCrud()
…by id
descending. To do that, open DashboardController and, anywhere inside, go to
Code -> Generate - or command+N on a Mac - select override methods and choose
configureCrud().
The Crud object has a bunch of methods on it... including one called
setDefaultSort(). That sounds handy…
Denying Access in a Controller
…it lives in
AbstractController. This method is so beautifully boring: it creates and
returns a new AccessDeniedException. This exception is the key to denying
access, and you could throw it from anywhere in your code.
Close that... and then go refresh. Yup, we get the…
Deployment & Supervisor
…the middle... there's a
spot that talks about supervisor. Copy the configuration file. We could put
this anywhere: it doesn't need to live in our project. But, I like to keep it in
my repo so I can store it in git. In..…
Using the Filesystem
…configured
as a global bind. And when you configure a bind, it must be used in at least
one place in your app. If it's not used anywhere, you get this error. It's kinda nice: Symfony is saying:
Hey! You configured this bind…
Flysystem <3 LiipImagineBundle
…we already have our Flysystem config all set up. Then, open our
liip_imagine.yaml file and, really, anywhere, paste!
This creates a loader called profile_photos - that name can be anything. Let's
use flysystem_loader. The critical part is the key flysystem: that…
Setting up with the Symfony Local Web Server
…anywhere, I'll move this into a global bin directory. By the way, you only need
to do these steps once on your computer... so you're done forever!
Unless we've mucked things up, we should now be able to run this from anywhere…
Abstracting a Class into 2 Smaller Pieces
…ShipLoader copy the entire queryForShips() and paste that
into fetchAllShipsData() and once again reference the pdo property:
Now we have a class whose only job is to query for ship stuff, we're not using it anywhere yet, but it's fully
ready to go…
Annotations
…bring up all the options that you
have in that spot. In fact, "control+space" can be used pretty much anywhere to show
you your auto-complete option - really handy.
This autocomplete works for two reasons. First, an annotation represents a real class.
Hold command…
Object-Oriented Intro: Classes and Objects
…including core
PHP functions like array_reverse() and our own like get_pets(). We
can call a function from anywhere in our code, so we say that they are available
“globally”.
But some functions aren’t global: they live inside an object and we call…
The Magical this Variable & currentTarget
…try this: console.log(e.currentTarget === this):
Refresh! And click anywhere on the delete link. It's always true.
There's a good chance that you've been using the this variable for years inside
of your listener functions to find the element that…
Creating a new Symfony 5 Project
…downloads a single executable file and, for me, puts it into my home directory.
To make it so that I can run this executable from anywhere on my system, I'll
follow the command's advice and move the file somewhere else:
Ok, try it…
x
513