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 arraycollection in 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 add annotations properties , after command doctrine:generate:entity setters , getters created, , relationships one-to-many|many-to-many in constructor class instantiated arraycollection class instead of simple array

    public 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

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -