Join Jon Peck for an in-depth discussion in this video Interacting with the entity manager, part of Up and Running with Symfony2 for PHP (2014).
Doctrine provides both the models and the work of persisting…data, or practically speaking, what interface do we use?…Doctrine's Entity Manager is the answer, which handles…the persistence of entities, including the storage…and retrieval of records within the database.…Within the controller, the entity manager is accessed…via a shortcut to the Doctrine service.…It's easy to just assign it into a variable…like em equals this for the controller, get Doctrine…for the Doctrine registry service,…then get manager to get the Entity Manager.…
The Entity Manager itself has a number of common methods.…Persist which takes an argument of an entity object…makes an entity instance managed…by Doctrine em persist in the database.…Basically, it's telling Doctrine that changes will occur.…It's also possible to remove an entity as well,…which will mark it as ready to be deleted.…Both persist and remove must prepare with flush which will…actually execute the queries against the database.…Practically speaking, flush synchronizes changes…
- Installing Symfony
- Creating a bundle from the console
- Customizing and generating database tables
- Generating controllers
- Creating, editing, and debugging entities
- Displaying and debugging a form
- Rendering content with templates
Skill Level Intermediate
Q: When trying to access the application, I receive an error stating "This script is only accessible from localhost." How can I get around this restriction?
A: The development front controller and configuration scripts are protected by default to only allow access from the localhost. Refer to the video titled “Exploring the Symfony layout” to see how to disable this security.