I need to create a filter like shopping store do (ebay for example).
What are the steps?
How to create queries for that filtering?
I need to create a filter like shopping store do (ebay for example).
What are the steps?
How to create queries for that filtering?
Explain clearer your needs, otherwise it is too much generic.
Database tables: Products, ProductCategories, ProductVendors
Products has some filed e.g. Price, Weight, Height, Vendor, Category … and more
I need to create a "filter" that would help to filter data on the site.
E.g. 1) Filter by Price between values
A generic answer might be
Design database tables according to the business requirements.
Create database tables.
Create ActiveRecord models for the tables … Gii will help you do it.
Create CRUD pages for the models … Gii will help you do it.
Modify/extend the models and the pages according to the business requirements.
Gii can provide you a good starting point. But you have to add/modify the Gii-generated code in order to satisfy your needs.
You can filter the products by the price range, by extending the ProductSearch model and its search method as well as the view script of index page. And you can filter the products by vendor or category also in the same way using relational query.
All of that is done.
I would like to know more about extending ProductSearch models. Any suggestions?
ProductSearch is a model for handling search parameters.
Initially it only has attributes that are from the base model Product.
And when some of them have been populated from the user input, then "search" method will construct hte filtering conditions according to the input.
You may add any attribute to ProductSearch.
For example, you can add “fromPrice” and “toPrice” to it. And then you can have those fields in your search form. By modifying “search” method accordingly, you’ll get the filtering functionality by price range.
Been said that another question starts (not sure if a new post should be created):
How to manage urlManager rules for ProductSearch requests?
In browser I get product/search?ProductSearch[globalSearch]=&ProductSearch[category]=climb
What will be the rule for that?