[TYPO3-mvc] how to add a method to another repository?
Kay Strobach
typo3 at kay-strobach.de
Sun Sep 30 17:06:21 CEST 2012
But Anja's solution is clean from the coding point of view :D
Regards
Kay
Am 30.09.2012 16:27, schrieb Claus Due:
> 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
>
--
http://www.kay-strobach.de - Open Source Rocks
TYPO3 .... inspiring people to share!
Get involved: http://typo3.org
Answer was useful - feel free to donate:
-
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KPM9NAV73VDF2
- https://flattr.com/profile/kaystrobach
More information about the TYPO3-project-typo3v4mvc
mailing list