1000 search results

Performance Optimization 2: Caching

…ObjectTranslator service. Down here in the translationsFor() method, this findBy() is what's making the queries. This is what we want to cache! Doctrine does offer some result caching, but it can get complex isn't as flexible as the Symfony Cache component. So, let…

4:32
Translatable Mapping

…and slick approach is to use PHP attributes. I'm all for slick and modern, so let's go with attributes. These will be similar to these Doctrine ORM mapping attributes. Ours will map translatable entities and properties. In our object-translation-bundle/src directory…

5:19
Pagination & Column Sorting

…go fix it! To use Pagerfanta, we'll install three libraries: composer require babdev/pagerfanta-bundle pagerfanta/doctrine-orm-adapter pagerfanta/twig Cool beans! Let's get the PHP side working first. Open src/Controller/MainController.php. The current page will be stored on the…

8:04
DTO -> Entity State Processor

…the item of type UserApi. We already talked about what's happening: the JSON is deserialized into a UserApi object. Good! Then the core Doctrine PersistProcessor is called because that's the default processor when using stateOptions. But... because our UserApi isn't an entity…

7:39
Decorating the CollectionProvider

…the failed response. Hmm: More than one result was found for query, although one row or none was expected. If you view the page source, this is coming from Doctrine... and eventually the core ItemProvider that we're calling. Back on the docs, the GetCollection…

7:12
Partial Handler Failures & Advanced Routing

…there's a problem removing this ImagePost from the database, Doctrine will throw an exception right here and the file will never be deleted. That's perfect: the row in the database and file on the filesystem will both remain. But if deleting the row…

4:35
State Processors: Hashing the User Password

…platform: we need some way to run code after our data is deserialized onto the User object, but before it's saved. In our tutorial about API platform 2, we used a Doctrine listener for this, which would still work. Though, it does some negatives…

6:55
MakerBundle & Autoconfiguration

…Ooh. There's a ton of stuff here for setting up security, generating doctrine entities for the database (which we'll do in the next tutorial), making a CRUD, and much more. Let's try one: how about we try to build our own new…

4:27
Activating 2FA

…good. No surprises, it adds one column to our table. Run that: symfony console doctrine:migrations:migrate Here's the plan. A user will not have two-factor authentication enabled by default. Instead, they'll activate it by clicking a link. When they do that…

5:34
AMQP Priority Exchange

…in different "queues". Then we can instruct our worker to first read all messages from whatever queue async_priority_high is bound to before reading messages from whatever queue the async transport is bound to. This did work before with Doctrine, thanks to this queue…

7:15
The Failure Transport

…an expanded format where you put the dsn on its own line and then add an options key with whatever you need below that. What options can you put here? Each transport type - like doctrine or amqp - has its own set of options. Right now…

5:37
Bundle Dependencies

…because we need the services the translation component provides, like the LocaleAwareInterface. Following that, run: symfony composer require doctrine/doctrine-bundle doctrine/orm Cool, these are the bare minimum dependencies our bundle requires to function. Now, it's time to add some development dependencies. Run: …

4:16
Simpler Validator for Checking State Change

…last tutorial, we put this above that same $dragonTreasures property, but inside the User entity. The validator would loop over each DragonTreasure, use Doctrine's UnitOfWork to get the $originalOwnerId, and then check to see if the $newOwnerId is different from the original. If it…

7:23
Pagination

…re only using this method right here at the moment, so rename it to createOrderedByVotesQueryBuilder()... and this will now return a QueryBuilder - the one from Doctrine ORM. I'll remove the PHP documentation on top... and the only thing we need to do down here…

9:19
Persisting to the Database

…question! We're only going to focus on creating objects and saving them. Doctrine will handle the insert queries for us. To help do this in the simplest way possible, let's make a fake "new Vinyl Mix" page. In the src/Controller/ directory, create…

6:43
Extending with Events

…it says "Updated By", "Null". Our goal is to set that field automatically when a question is updated. A great solution for this would be to use the doctrine extensions library and its "blameable" feature. Then, no matter where this entity is updated - inside the…

8:03
How Entity Controller Arguments Work

…is that code? At first, you might think this is another argument value resolver. But, there's nothing in that list that mentions "doctrine" or "entity". In reality, this is working via a different system. If we refresh now, the page still works. But if…

4:54
Clean URLs with Sluggable

…it does! It adds slug including a UNIQUE INDEX for slug. And when we run it with symfony console doctrine:migrations:migrate it explodes... for the same reason as last time: Not null violation. We're adding a new slug column to our table that…

6:48
Hello Flex: Moving Final Files

…console doctrine:migrations:status Ah! I guess not! It says that my migration class wasn't found: Is it placed in a DoctrineMigrations namespace? Bah! I don't know! Our files have an Application\Migrations namespace. What's going on? Open the config/packages/doctrine

4:00
Autowiring & Service Deprecations

…In Symfony 3, when Symfony saw a type-hint - like EntityManager - it would first look to see if there was a service or alias in the container with that exact id: so Doctrine\ORM\EntityManager. If there was not, it would then scan every service…

9:17