1000 search results

Custom Validation, Callback and Constraints

…Event entity that looks like this (with some extras, like getter and setter methods): // src/KnpU/QADayBundle/Entity/Event.php namespace KnpU\QADayBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity(repositoryClass="KnpU\QADayBundle\Entity\EventRepository") / class Event { @ORM\Column(name="id", type="integer") …

3:56:28
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
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
Bundle Configuration

…reference With no arguments. This lists all the loaded bundle's, and their configuration key (or extension alias). DoctrineBundle, alias doctrine, DoctrineMigrationsBundle, alias doctrine_migrations. Here's our bundle: ObjectTranslationBundle, alias object_translation. Hmm, I'd like to prefix it with symfonycasts, like the Tailwind…

3:18
Setup & Ways to Extend API Platform

…validation, voters, and more. That's all good stuff. But, so far, all of our #[ApiResource] classes have been Doctrine entities. And that's fine! But as your API starts to look different from your entities, making that work adds complexity: serialization groups, extending normalizers…

4:39
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
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
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
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
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
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
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
Field Types & Options

…we now know that, because we've bound our form to our entity, the form type "guessing" system is able to read the Doctrine metadata, notice that content looks like a big field, and "guess" that it should be a textarea. Field type guessing is…

4:45
Creating an Entity Class

…need a use statement for it. This will look weird, but add a use for a Column class and let it auto-complete from Doctrine\ORM\Mapping. Remove the Column part and add as ORM: Every entity class will have that same use statement. Next…

5:29
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
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
stateOptions + entityClass Magic

…darn it, let's yolo this thing and try to! Head over to UserApi, say provider, and point to CollectionProvider (the one from Doctrine ORM). Let's see what happens! At the browser, go to the endpoint directly - /api/users.jsonld. And... we get an…

10:07
Testing Messenger

…you guessed it, Zenstruck! composer require zenstruck/messenger-test --dev Cool! This messenger-test library adds a special Messenger transport called test. We'll still use Doctrine by default, but now open up config/packages/messenger.yaml. Uncomment the async transport, which uses MESSENGER_TRANSPORT…

7:18
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