1000 search results

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
Article Admin & Low-Level Access Controls

…you see this "Proxies" thing, ignore it. This is an internal object that Doctrine sometimes wraps around your entity in order to enable some of its lazy-loading relation awesomeness. The object looks and works exactly like User. Second, the error itself basically means that…

7:14
Custom User Method

…the new file: And... yep! It looks perfect. Move back to your terminal one more time and run: php bin/console doctrine:migrations:migrate Excellent! Now that we have the new field, let's set it on our dummy users in the database. Open UserFixture…

6:18
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Dynamic Roles

…ORM\Column annotation and set its type to json_array: This is really cool because the $roles property will hold an array of roles, but when we save, Doctrine will automatically json_encode that array and store it in a single field. When we query…

4:10
The Mysterious "User Provider"

…the user provider is responsible for loading the User from the session and making sure that it's up to date. In Doctrine, we'll want our's to re-query for a fresh User object to make sure all the data is still up…

2:18