The Query Builder
…accidentally remove something
you added earlier. So, always use andWhere(). Doctrine is smart enough to figure
out that, because this is the first WHERE, it doesn't actually need to add the
AND.
Inside of andWhere(), pass mix.genre =... but don't put the…
Query Joins & Solving the N+1 Problem
…selects from comment, but it does have the INNER JOIN to article!
We can now easily reference the article somewhere else in the query. Inside
the andWhere(), add OR a.title LIKE :term:
That's all you need. Move back and refresh again. It works…
Request Object & Query OR Logic
…always use andWhere() and put all the OR logic
right inside: c.content LIKE :term OR c.authorName LIKE :term. On the next line,
set term to, this looks a little odd, '%'.$term.'%':
By putting this all inside andWhere() - instead of orWhere() - all of that…
Search, the Request Object & OR Query Logic
…I'll show you what
I mean when we see the final query. The point is that if you need an OR in a
WHERE statement, you should still use andWhere(). Yup, we can say:
answer.content LIKE :searchTerm OR and then pass another expression…
Joins and addSelect Reduce Queries
…this
should be a really easy query. I'll copy the search() function, then simplify
things in the andWhere: cat.id = :id. We want to keep the leftJoin()
and the addSelect to remove the extra query. Update setParameter to set
the id placeholder:
The…
Stimulus: Writing Pro JavaScript
…because modern CSS is amazing.
Over on the aside element, add a new CSS class - it could go anywhere - called
transition-all.
That's a Tailwind class that activates CSS transitions. This means that if
certain style properties change - like the width suddenly being set…
Functions!
…-- index.php -->
Just like your new pup, a function can really go
anywhere. And variables can be used as arguments.
Remember, $cleverWelcomeMessage represents our string message, so this
is the same as passing the string directly…
Testing a Service
…like controllers, repositories & services, nobody
is using the LockDownHelper service. We're not autowiring it into a controller
or a service anywhere. And so, Symfony removes this from the container... which
means that it's not there in the test.
The fix for this is…
Composer
… By including Composer’s autoloader, the
Finder library - as well as the PHP classes for any other libraries we included
via Composer - are made available to us automatically.
To make our third-party classes available anywhere, it would be even better
to include the autoload…
API Token Scopes
…form, they
can still use this operation, even though they won't have that exact role. That
is where ROLE_FULL_USER comes in handy.
Open config/packages/security.yaml and, anywhere, add role_hierarchy... I
recommend spelling it correctly. Say ROLE_FULL_USER. So…
Global vs CRUD-Specific Configuration
…ROLE_ADMIN. We'll talk more later about how to secure
different admin controllers with different roles... but at the very least, you need
to have ROLE_ADMIN to get anywhere, which is awesome.
But one important point: adding this access_control was necessary. Why?…
HTML dialog for Modals
…Actually, we can put it down here on
the dialog. Add a new action: click->modal#clickOutside:
I bet that looks odd - it'll be called whenever we click anywhere in the dialog -
so let's go write that method. Say clickOutside(), give it an…
The Request Object
…Request object. And there are two ways to get it.
The first is by autowiring a service called RequestStack. Then you can get the
current request by saying $requestStack->getCurrentRequest().
This works anywhere that you can autowire a service. But in a controller, there's…
Pub Sub Event Class & Subscribers in Symfony
…EventSubscriberInterface and... done!
Symfony will automatically register it. To dispatch an event, create a new event
class and dispatch that event anywhere in your code.
If we try this again (I'll exit the battle first)... it only outputs once. Great!
And... what are the…
AssociationField for a "Many" Collection
…Yup! Now it's saying:
Hey Ryan! Go add that __toString() method!
Ok fine! In Answer, anywhere in here, add public function __toString(): string...
and return $this->getId():
Now... we're back! And if we type... well... the search isn't great because
it's…
Behat for Testing
…To see it, run
the same command with a -dl option:
$ php vendor/bin/behat -dl
Anywhere you see the quote-parentheses mess that’s a wildcard
that matches anything. So as long as we write scenarios using this language,
we can test without…
All About services.yaml
…service ID. This is done for simplicity... but also for
autowiring. When we try to autowire MixRepository into our controller or anywhere
else, to figure out which service to pass us, Symfony will look for a service
whose ID exactly matches App\Service\MixRepository. So…
The Entry Point: Inviting Users to Log In
…words:
it's making us choose.
Copy the entry_point key... then, anywhere under the firewall, say
entry_point: and then point to the LoginFormAuthenticator service:
Technically we can point to any service that implements
AuthenticationEntryPointInterface... but usually I put that in my authenticator.
Now..…
Customize Error Messages & Adding Logout
…intercept that request, log out the user,
and redirect them somewhere else.
To activate that magic, open up config/packages/security.yaml. Anywhere under our
firewall, add logout: true:
Internally, this activates a "listener" that looks for any requests to /logout.
And actually, instead of…
Vue Instance & Dynamic Data
…does exactly what Vue normally does. If you look at this, you might start to wonder:
why do we need a template option at all? We're just reading it in render()...
so it could live anywhere. Let's try that! Remove the option, and…
x
513