[TYPO3-mvc] get records from own model pages

Franz Koch typo3.RemoveForMessage at elements-net.de
Tue May 3 19:28:43 CEST 2011


Hey Georg,

...
> a) i could create in the page model a function getRecords where i create
> an instance of the records repository and return all records with
> pid=$this->pid
> b) Iterate in the controller trough all pages. In the loop i call find
> Method of the records-repository and do something like
> pages->setRecords(foundRecords) (not sure if i have access to the model
> via the repository)

I think both would be fine if they fit your needs, whereas a) is in my 
eyes the cleaner approach. Don't forget to "cache" the records inside 
your page model (using a private property) so that you don't have to 
query the repository over and over again if getRecords is triggered 
several times (like first in a if-VH and then for rendering).

> .. i could also create a new field in pages table with relation to the
> records but i don't want this because i have the relation already via
> the pid field of records ..

That would of course be the cleanest solution, but as you mentioned 
you'd need a extra DB field on the pages table which you don't want to 
add - so I'd use approach a). The only thing you could think about with 
solution a) is, that instead of messing around with a repository inside 
a model, it might be a bit nicer to move the repository calls (and 
probably also the caching logic) to a service and just call the service 
method from within your page models (doing so don't forget to declare 
your service as singleton for this use case).

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list