1000 search results

Publish State Change Validator Logic

… Or true to false? Or maybe it's not changing at all because the PUT request is only updating other fields. And hey! We already know how to get the original data from Doctrine! We did it in CheeseListingDataPersister: Oh, and by the way: if…

8:26
Completely Custom Resource

…directory, create a new class called DailyStats: And yes, I'm putting this in the Entity/ directory even though this isn't going to be a Doctrine entity. That's totally allowed and it's up to you if you like this or not. If…

5:25
Attachments with Async Messenger Emails

…are a bunch of deprecation notices, but the tests do pass. However, run that Doctrine query again to see the queue: Uh oh... the email - the one from our functional test to the registration page - was added to the queue! Why is that a problem…

3:57
Collection Magic with Criteria

… But... there's a problem. If we did this, Doctrine would query for all of the comments, even though we don't need all of the comments. If your collection is pretty small, no big deal: querying for a few extra comments is probably fine…

7:45
Pagination

…way long. Not only will this page become hard to use, it will quickly slow down until it stops working. If you ever need to query and render more than 100 Doctrine entities, you're going to have slow loading times. If you try to…

9:19
Saving Entities

… And, good news! This is probably one of the easiest things to do in Doctrine. Let's create a new controller called ArticleAdminController. We'll use this as a place to add new articles. Make it extend the normal AbstractController: And create a public function…

7:40
Query Logic Re-use & Shortcuts

…is to isolate the query logic that we need to share into its own private method. At the bottom, create a private function addIsPublishedQueryBuilder() with a QueryBuilder type-hint - the one from Doctrine\ORM - and $qb: Next, go up, copy that part of the query…

6:40
Activating Timestampable

… First, we need to activate it, which again, is described way down on the bundle's docs. Open config/packages/stof_doctrine_extensions.yaml, and add timestampable: true: Second, your entity needs some annotations. For this, go back to the library's docs. Easy enough…

4:03
Saving Relations

…to Doctrine. At the top, use the $manager variable: Then, $manager->persist($comment1): If we stop here, this is a valid Comment... but it is NOT related to any article. In fact, go to your terminal, and try the fixtures: php bin/console doctrine:fixtures…

4:35
Integration Tests

…if you mock everything... there's nothing really left to test For example, how would you test that a complex query in a Doctrine repository works? If you mock the database connection then... I guess you could test that the query string you wrote looks…

9:18
Clearing the Database

…end of kernel.project_dir! Now, find your terminal and create the var/data directory: Next, create the schema php bin/console doctrine:schema:create --env=test And, congrats! You are the owner of a fancy new var/data/test.sqlite file! Take good care of…

6:19
Handling Object Dependencies

…$this->assertCount(0) matches $enclosure->getDinosaurs(). Ok, good start! Next, inside Entity, create Enclosure. This will eventually be a Doctrine entity, but don't worry about the annotations yet. Add a private $dinosaurs property. And, like normal, add public function __construct() so that we can…

6:46
Override Controllers

…and I want you to know both. Open the User entity. It has an updatedAt field: To set this, we could use Doctrine lifecycle callbacks or a Doctrine event subscriber. But, I want to see if we can set this instead, by hooking into EasyAdminBundle…

7:11
More about List Field Types

…which controls that dataType config. There are a bunch of built-in types, including all of the Doctrine field types and a few special fancy ones from EasyAdminBundle, like toggle. The "toggle" type is actually super cool: it renders the field as a little switch…

6:06
Config.yml: Control Center for Services

…twig and doctrine - corresponds to a bundle that is being configured: All of this stuff under framework is configuration for the FrameworkBundle: Everything under twig is used to control the behavior of the services from TwigBundle: The job of a bundle is to give us…

4:24
Caching in the prod Environment Only

…the dev environment only? Yes! Copy the doctrine_cache from config.yml and paste it into config_dev.yml. Next, change type from file_system to array: The array type is basically a "fake" cache: it won't ever store anything. Yea, that's it…

3:16
Parameters: The Variables of Configuration

…and set that to a value. Why is this cool? Because you can then reuse that value in any other file by saying %locale%. Look under the doctrine key: Hey, a bunch more, like %database_host% and %database_port%. These are set just like locale…

3:29
parameters.yml & %kernel.root_dir%

…the path from it. Earlier, just to show off, we configured the DoctrineCacheBundle to store the markdown cache in /tmp/doctrine_cache: Referencing absolute paths is a little weird: why not just store this stuff in Symfony's cache dir? Ok, ok, the bundle actually…

4:48
Controlling Data / Fixtures in a Test

…is stored statically on the parent test class: // src/Yoda/UserBundle/Tests/Controller/RegisterControllerTest.php // ... public function testRegister() { } Now, grab the Doctrine entity manager by getting the doctrine service and calling getManager. If you’re not comfortable with what I just did, don’t worry…

3:23
After-dinner Mint

…Let’s pretend that the email field isn’t requied. Remove the NotBlank constraint from it and set a nullable=true option in the Doctrine metadata. Don’t worry about updating your schema - this change is just temporary: // src/Yoda/UserBundle/Entity/User.php // ... /** @ORM\Column…

3:35