Catalog with filters

Hello!

I am relatively new to Yii2, but have worked with Yii1 before. Here’s what I’m trying to accomplish:

6187

mockup.png

A product catalog with filters.

Here’s my model structure:

6188

model_structure.png

There are Products, Categories, Properties and Values. So Samsung Galaxy is a Product of category Smartphone. There’s a Screen Size Property and there are several Values of this Property, like 5", 6" and 10".

The models are pretty much what Gii has generated automatically. The products are shown using ListView.

ProductSearch model is what’s giving me trouble, though. The example uses a form for this model, but I’d like to make all those fields clickable urls. The question is, what’s the easiest way to do it?

Let’s say 10" value has id 456. So if my current instance of ProductSearch has a category id of 123 when I print the list of those filters, I need a link like index.php?r=somecontroller/index&category=123&filter=456.

This spawns two questions:

  1. Is there a way to get these urls automatically?

  2. How do I pass multiple values of the same parameter? So if 10" is 456 and 6" is 567, how do I pass that filter is 456 and 567?

I may be reinventing the wheel here, but yii2 examples are few and far between :(

I don’t have a good answer for you, but when in doubt I always look at what the experts do… Head to amazon, newegg, ebay and see how they implement it. Instead of specific Ids for listview it seems most use range parameters (price between X and Y, size between A and B, etc).

You don’t even have to use $_GET parameters but they have the advantage of being bookmark-able.

Thanks you for your reply!

I’m interested in the low-level implementation of the filtration concept using yii. So my doubts are not whether I should use single filter values or ranges, but which yii objects to use and how.

Anyway, I think I have an idea. The implementation should be very similar to the LinkPager object: it has a state (current page) and it knows the right controller/action to use and it generates urls for all other possible states (other pages).