[TYPO3-mvc] how to add a method to another repository?

Claus Due claus at wildside.dk
Sun Sep 30 16:27:24 CEST 2012


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


More information about the TYPO3-project-typo3v4mvc mailing list