Le 05/04/2011 19:59, Ruben de Vries a écrit :
I've been playing around with sf2 lately and been looking at code from
the various github projects but I'm still not really sure what (and
more importantly *why*) is going on with the Model classes.
I've picked up on the concept that Entities should remain fairly
untouched from complex (business) logic, but I can't really figure out
where I should leave the logic then?
You could look at https://github.com/ornicar/lichess the main bundle of
this project is in src/Bundle/LichessBundle. you will see that ornicar
created lots of namespaces to organize his code.
I think the FriendsOfSymfony/UserBundle is a good example to look at,
but it looks really weird from my point of view what they do with the
models and entities.
At least how I understand is that they make the Entity extend the
Model so that the complex (business) logic is placed in the Model
class instead of the Entity but they can still access that logic when
they've fetched Entities through doctrine ORM.
They seem to do the same for the EntityManager classes.
The only reason why we have a Model namespace is that it avoids
duplicating the logic between the Entity and the Document namespaces as
the bundle supports both ORM and ODM.
The real questions I have (to make it a bit easier to answer) are;
1) What stuff *should* be placed in the normal Entity? (or maybe it's
easier to give a clearer definition of what shouldn't?)
An entity is mainly about storing data. so the basic one only have
getters and setters
2) Is the Entity extending a Model class the 'way to go'?
Asuming it is;
If you only need to support the ORM, no. The "Model" namespace has no
meaning in Symfony2 conventions.
3) What stuff should be placed in the Model and what should go in the
EntityManager?
4) Why does the EntityManager extend a corresponding manager from the
Model namespace too?
the UserManager of FOS UserBundle is our way to put the logic. The first
version used the Doctrine repositories but then the bundle was tied to
Doctrine (its name was DoctrineUserBundle at this time). The current
implementation is not tied to Doctrine: we could implement a Propel
version for instance without needing a whole new bundle.
You don't need to use such a layer in your project. Using the Doctrine
repository will be fine in most cases. You could look at
https://github.com/knplabs/symfony2bundles (the source dode of the
http://symfony2bundles.org/ website) or https://github.com/Yrch/Yrch (my
own WIP project) to have some examples.
I hope somebody can shine a light on this, this is what curently makes
it hard to get started with sf2 (if you ask me); finding the right/
correct way to do things.
Something that the sf1.4 jobeet tutorial (and more sf1.4 books /
blogs / tutorials) really helped a lot with,since it contained a lot
of reasoning why things are done the way it is done.
This will be done but it cannot be done until the framework become quite
stable to avoid having to rewrite it.
For me that is a big reason to use symfony; it encourages using best
practices and becoming a better programmer (where most other
frameworks only tell you what to do to get the job done like a
brainless script kiddie)
--
Christophe | Stof
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en