doctrine2 - ArrayCollection in Symfony -
since i'm quite new symfony , doctrine got maybe stupid question ;-)
can use simple words explain collections (especially arraycollections in entities) me? , when , how use them? (maybe in simple example)
couldn't figure out quite in docs...
thanks in advance.
so arraycollection simple class implements countable, iteratoraggregate, arrayaccess spl interfaces, , interface selectable made benjamin eberlei.
not information there if not familliar spl interfaces, arraycollection - permit save object instances in array form in oop way. benefit of using arraycollection, instead of standard array save lot of time , work, when need simple methods count, set, unset iterate object, , of very important:
- symfony2 uses
arraycollectionin core , doing lot of things if configure well:- will generate mapping relationships "one-to-one, many-to-one ... etc"
- will bind data when create embedded forms
when use it:
usually used object relationship mapping, when using
doctrine, recommended addannotationsproperties , after commanddoctrine:generate:entitysetters , getters created, , relationshipsone-to-many|many-to-manyin constructor class instantiatedarraycollectionclass instead of simplearraypublic function __construct() { $this->orders = new arraycollection(); }an example of use:
public function indexaction() { $em = $this->getdoctrine(); $client = $em->getrepository('acmecustomerbundle:customer') ->find($this->getuser()); // when need lazy load orders // customer one-to-many relationship in database // use it: $orders = $client->getorders(); //getorders arraycollection }actually not using directly use when configure models when setting setters , getters.
Comments
Post a Comment