Situation:
There is simple User
class which is Doctrine entity (I skipped comments to keep the code short):
class User {
protected $iUserId;
protected $sName;
}
Question:
How to retrieve collection of objects of class User
from the controller?
Follow up:
Until now, we were creating methods like getUsers()
in User
class which gets data from DB, creates User
class objects and returns it.
Now, I'm wondering if it's not a better solution to create class like UserCollection
which would handle data retrieving and creating User
objects? Maybe I should make use of \Doctrine\Common\Collections\Collection
class somehow?
What I'd like to accomplish is easy way to handles i.e. where
clauses. UserCollection
class could have QueryBuilder
object on which I could operate from controller like this:
$oUserCollection = new UserCollection();
$oUserCollection->setWhere( 'u.iUserId = 1' );
$aUsers = oUserCollection->getUsers();
...
Please share your thoughts on that topic.
Update: Doctrine provides a concept of repositories of entities which I think maybe the solution I'm looking for.