511 search results

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…

6:03
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…

8:44
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…

9:01
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…

8:00
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…

5:51
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…

5:28
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?…

9:13
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…

6:28
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…

13:18
Popover!

…and paste: Next, create an endpoint for this. In src/Controller/PlanetController.php, anywhere, I'll paste in a route and controller: Nothing special: it queries for the Planet and passes it to the template. In that template, adjust the variables. Instead of voyage.planet…

11:44
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…

7:31
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…

6:34
Override all the Templates!

…of using the first method to override this - which would work - let's do something different. Copy this template and create our override template... which could live anywhere. How about in templates/admin/field/... and call it id_with_icon.html.twig. Paste the contents..…

6:47
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…

7:33
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..…

6:45
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…

14:00
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…

10:27
Security Voter & Entity Permissions

…do have control over that query. Open up UserCrudController and, anywhere, I'll go near the top, override a method from the base controller called createIndexQueryBuilder(). Here's how this works: the parent method starts the query builder for us. And it already takes into…

8:36
Form Submit Confirmation Controller

…the item is gone! But I think we can make this even more awesome. How? By making our controller configurable - like the text that it displays - so we can truly reuse it anywhere in our app. Even in this situation, saying "yes, delete it" on…

6:22
Autowiring Dependencies into a Service

…is something that we're gonna to do over and over again. The benefit is that we now have a beautiful service - a tool - that we can use from anywhere in our app. We pass it the markdown string and it takes care of the…

6:45