[TYPO3-mvc] Using Repositories "standalone"
Franz Koch
typo3.RemoveForMessage at elements-net.de
Fri Aug 13 03:32:23 CEST 2010
Hey Michael,
> We are (re-)writing an extension for generating lists using ExtBase. One
> feature of this extension should be a possibility to render domain
> objects in a list. A possible gimmick could be a viewhelper that renders
> a collection of objects given as parameter.
is this extension itself also based on extbase? Because in your code
example you called the dispatcher directly, which is only needed if not
in extbase context.
> The extension also contains filters and pagers that can be used on those
> objects. So I cannot put a collection of objects into any kind of list
> renderer and let the extension do the job, but the extension itself has
> to "generate" the data depending on current pager and filter settings.
>
> So here comes my question: Is there any "easy" way to get an instance of
> a repository without faking a dispatchin action. What I'm doing at the
> moment might look a little weird to you...
Why don't you do something like this, if you're already inside extbase:
/**
* Is rendering a list of various objects, filtered by the demand object
* @param $demand Tx_ExtKey_Domain_Model_Deman The filter demand that
is holding the configuration of your filter
* @param $page integer The page offset to display
function listAction(Tx_ExtKey_Domain_Model_Demand $demand, $page = 1) {
$listItems = array();
foreach ($demand->getObjectTypes() as $objectType) {
$repositoryClassName =
'Tx_YourExt_Domain_Repository_'.ucfirst($objectType->getName()).'Repository';
$repository = $this->objectManager->get($repositoryClassName);
$items = $repository->findDemanded($demand);
$listItems = array_merge($listItems, $items);
}
// apply pagination-limit if needed, or if only one object type
// can be rendered at a time, add pagination stuff probably in
// your findDemanded method of the repository
$this->view->assign('listItems', $listItems);
}
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list