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:
<?php
namespace Acme\SampleBundle\Entity\Subfolder\EntityClass
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:
<?php
public function sendByEmail() {
// Do stuff
}
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);
Entities are models stored in a relational database. Documents are models stored in a document databases (MongoDB, for example).
If you don't want to bend your model to a particular namespace depending on what storage type you're using, here's what I suggest. Create the Model
namespace for your model classes. If you choose to use a relational database, you extend your model class and put it into the Entity
namespace, providing mapping information in an external file. If you later decide to move to a document database, you do the same, but use the Document
namespace.
For a good example of this idea see FOSUserBundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With