I would like to be able to use the PersistentObject described here http://www.doctrine-project.org/blog/a-doctrine-orm-odm-base-class.html during development of a Symfony2 project, to avoid creating and deleting getters and setters endlessly whilst the database and entity design are in flux.
Where in a Symfony2 project does one 'configure' the ObjectManager, as suggested in the brief documentation (code quote below)? Should it be in the controller, and if so, what would it look like?
$entityManager = EntityManager::create(...);
PersistentObject::setObjectManager($entityManager);
I cannot find any working examples (although I did find this parallels example for the Zend2 framework on stackoverflow: Using PersistentObject from Doctrine in Zend Framework
Thanks for your time!
The PersistentObject is an object which you don't manually have to persist. It thereby provides magic getters and setters using php's
__call()
method.You simply extend the Object in your entity class and use it inside your controller. without the need to generate getters and setters.
example entity
example controller action
You get the doctrine entity manager inside a symfony controller using one of ...