[TYPO3-mvc] Passing filters by array or custom object? Which is the better approach?

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jan 11 15:37:31 CET 2010


Hi,

> The page reloads and displays now the items which are tagged with
> 'Wooden Stuff'. Now he want's to show these items, but only the ones
> which are cheaper than € 100. Again he clicks on 'Price below €100'
> and the page reloads. Now he sees all the 'Wooden Stuff' items which
> cost less than € 100.

That's clear so far.

> In this example I call the view action three times:
...
check

> Inside my view action I call an appropriate query of my repository,
> which returns me only the products which match my filter options.

why do you do it inside your view? Isn't the controller responsible to 
trigger the repository and then assign the products as variable to the view?

function filterAction($filter,...) {
	$filteredProducts = $this->productRepository->findByCriteria($filter);
	$this->view->assign('products',$filteredProducts);
}

So your view doesn't have to deal with filtering the products in the 
repository - the view is only responsible for rendering those products 
and rendering the links to filter stuff (maybe by using dropdowns for 
filtering?).

> I don't know how to realize that, without calling the view action
> passing it the options chosen by the user. My question is how to pass
> them.

I think I'd pass the pure settings/filter options by array as long as 
you don't need any logic inside the filter settings (like dependencies: 
if filter "x" is set, then option "y" doesn't have this or that entry, 
so only return those values to the view).

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list