[TYPO3-mvc] Using ObjectStorage properly
Felix Oertel
mehl at foertel.com
Thu May 6 13:23:37 CEST 2010
Hi,
Am 06.05.10 11:48, schrieb Søren Malling:
> I've come to the part where I need to get the members of the currenct
> club object.
yah, normally they get mapped as constraints ... let's see
> I created a property in my club model
good start ;)
>
> /**
> * Members of club
> * @var
> Tx_Extbase_Persistence_ObjectStorage<Tx_Ysmenmembers_Domain_Model_Member>
> */
> protected $members;
looks good. does the database have a field "members"? if yes, please
post TCA-config, if not, please post mapping-TS.
> public function __construct() {
> $this->members = new Tx_Extbase_Persistence_ObjectStorage();
> }
not sure about that, but you might simply skip that. you need this, if
you want to work with an empty objectStorage, but as you just use it in
a property, the datamapper will build an objectStorage (filled with
items or empty) for you anyway.
> /**
> * Get members of club
> * @return
> Tx_Extbase_Persistence_ObjectStorage<Tx_Ysmenmembers_Domain_Model_Member>
> */
> public function getMembers() {
> return $this->members;
> }
And you've got a set(), aight?
> This is where I'm stucked. How does this objectstorage know what data
> to return?
It takes the type-hint (the part in <>), tries to get that model and
then fetches the objects. if this is not in-depth enough, please let me
know, I'll explain a little bit deeper if this is of interest*. ;-)
> And should this be handled in a different way, using a memberRepository instead?
you don't have to, the way you are going is perfectly ok. I do it the
same way with categories of an image ...
you forgot to tell us, what exactly is your problem. ;-) don't you get
data at all? an exception?
regards, foertel
* and of course everybody feel free to join talks/workshops on t3camp10
hamburg and t3dd10 elmshorn and talk to me or to anyone else willing to
help, I guess there will be quiet some of know-how-people ;)
More information about the TYPO3-project-typo3v4mvc
mailing list