[TYPO3-mvc] how to add a method to another repository?
Stefano Cecere
scecere at krur.com
Mon Oct 1 08:33:11 CEST 2012
Hi Claus
your solution is what i was trying to do (injecting my query inside the
news repository)
i could make everything work by my own subclass.. but now i'll convert
to this.
PLEASE: have you an Amazon wishlist anywhere or something alike?
you are giving so many useful tips.. that i need to give you something
back! :)
stefano
On 30/09/12 16:27, Claus Due wrote:
> Hi Stefano,
>
>> i want to search within another extension repository by a custom search query (say it is the "news" ext)
>>
>> the only option i see is to subclass the model i want (say "news"), and then search within it.
>>
>> do you agree?
>
> I don't agree :)
>
> The best option imho:
>
> $query = $this->foreingRepositoy->createQuery();
> $query->matching($query->equals('somefield', 1));
> $queryResult = $query->execute();
> $this->view->assign('objects', $queryResult);
>
> You don't want to extend the Repository, since that will require you to also extend the model and configure mapping which is complete overkill. What you need is the Query object as pre-configured by the original Repository.
>
> You can wrap this in another "Repository" which is just a shell, i.e. instead of extending the News Repository, just inject it in your own repository and provide proxy methods as needed. I prefer the $originalRepository->createQuery() myself.
>
> Cheers,
> Claus
>
--
-- --- ----- -------
Stefano Cecere
KRUR studio - http://krur.com
More information about the TYPO3-project-typo3v4mvc
mailing list