1000 search results

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
Filters

…put anything in DiscontinuedFilter yet, but most of the work is done. That ClassMetadata argument is your best friend: this is the Doctrine object that knows everything about the entity we're querying for. You can read your annotation mapping config, get details on associations…

10:29
Symfony Overlord: The Service Container

…With such a tiny list, it’s easy to spot the entity manager service: doctrine.orm.entity_manager. This is the “name” of the service and we use it to get this object out of the service container. We’ve been getting the entity manager…

4:58
More with ManyToMany: Avoiding Duplicates

…an error! SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘4-4’ for key ‘PRIMARY’ Our User is once again added as an attendee to the Event. And when Doctrine saves, it tries to add a second row to the join table. Not cool! Adding…

2:51
ManyToMany Relationship

… Like with a ManyToOne, we just need an annotation that tells Doctrine what type of association this is and what entity it relates to: // src/Yoda/EventBundle/Entity/Event.php // ... /** @ORM\ManyToMany(targetEntity="Yoda\UserBundle\Entity\User") / protected $attendees; Whenever you have a relationship that…

2:37
Adding createdAt and updatedAt Timestampable Fields

…library does this for us. It’s called timestampable, enable it in config.yml: # app/config/config.yml # ... stof_doctrine_extensions: Head to the timestampable section of the documentation to see how this works. We already have the Gedmo annotation, so just copy in the…

1:41
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
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
User Serialization

…object hidden in our entity causes serialization to fail. The entity manager contains a database connection and other information that just can’t be serialized. Using the Serializable Interface¶ We need to help Doctrine out. Start by adding the Serializable interface to the User class…

2:16
The UserProvider: Custom Logic to Load Security Users

…logging in now! Ah, a great error: The Doctrine repository “Yoda\UserBundle\Entity\UserRepository” must implement UserProviderInterface. The UserProviderInterface¶ Without the property, Doctrine has no idea how to look up the User. Instead it tries to call a method on our UserRepository. But for that…

3:15
Repository Security

…Serializable Note Actually, if you don’t set the repositoryClass option, Doctrine just gives you a base repository class for that entity. Repositories are where query logic should live. We could create methods like findActiveUsers, which would query the database for users that have a…

4:20
Adding Dynamic Roles to each User

…database, these are stored as a JSON string. Doctrine takes care of converting back and forth between the array and JSON. Now, just update the getRoles() method to use this property and add a setRoles method: public function getRoles() { } public function setRoles(array $roles) { } Cool…

4:56
Saving Users

…class (LoadEvents.php) into the UserBundle, rename it to LoadUsers, and update the namespaces: // src/Yoda/UserBundle/DataFixtures/ORM/LoadUsers.php namespace Yoda\UserBundle\DataFixtures\ORM; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Yoda\UserBundle\Entity\User; class LoadUsers implements FixtureInterface …

3:37
Entity Security

…one: # app/config/security.yml security: I’m just inventing the our_database_users part, that can be anything. But the entity key is a special built-in provider that knows how to load users via a Doctrine entity. Yea, and that’s really it…

4:32
Contentful: Loading Data from an External CMS

…what we're doing, it's a pretty quick process and would give us a lot of power on our site. But one of the beautiful things about Layouts is that our value types can come from anywhere: a Doctrine Entity, data on an external…

8:02
Final Upgrades & Cleanups

…s possible that some recipes have new versions we can update to. Run: composer recipes:update Oh, whoops! I need to commit my changes: git commit -m 'upgrading doctrine/dbal from 2 to 3' Perfect! Now run composer recipes:update and... cool! There are two…

6:33