I am currently learning how to use the symfony2 framework.
Going through the cook book, I am starting to have a basic understanding of how everything fits together.
However, I have 2 questions regarding Entities, which I believe are models in the MVC pattern:
-
In the documentation, there seems to be a lot of talk about entities using doctrine as ORM. If I have an entity/model that does not require any ORM, is this still considered an “entity”?
-
In most tutorials I have seen, entities are often all thrown into a folder called “entities” under the application bundle. With many entities in an application, I feel that this can become quite messy and unorganized. How can I group and organize entities?
Cheers 🙂
regarding your question how to organize your model classes:
You may add Subfolders to “Entity” folder, then just follow that scructure in your namespace definition like:
regarding your question to work without orm: that’s simple, just don’t use it.
your classes will behave like “normal” classes do..
But you will need some kind of interface to that, like EntityManager in Doctrine2, too.
I would always prefer the use of ORM/ODM..
That case I would just add a simple method to your entity class:
You dont have to persist (save to DB) stuff at all. Note that in symfony1.4 there was a
save()method on entities. In Symfony2 stuff is saved through$entityManager->persist($entity);