views:

121

answers:

2

Hi there, I'm pretty new to CakePHP and was missing a crucial feature not generated as scaffold: filtering.

What do I have to do to provide dropdowns or multi-selects on the index pages for each field that is a (foreign) key, thereby allowing to filter the table ("OR" inside multi-select, "AND" between different multi-selects, if any)?

From what my websearch has shown me there are many more people trying to accomplish the same thing, although I couldn't find anything that would work for me because either they have text fields and do wildcard filtering, or the plugins they propose only work for 1.2 whereas i now started with 1.3 etc. etc.

Can someone alleviate the confusion and maybe present some working code or direct me to the definitive guide[tm] where this matter has been solved?

Thx

A: 

It seems to me that scaffolding is provided as-is. If you find any helper accomplishing this, many would be interested, I'm sure. But scaffolding is not really meant satisfy such "complex" requirements, it just lists the row in the model. Although it shouldn't be difficult to program what you want: using cake from the console it can generate you all the code that scaffold does, you only have to add your filters.

sibidiba
Well yeah I was as far as generating the code, without which it is impossible to use the solutions that are out there[tm]. Unfortunately none of them seems to do exactly what I ask, which leaves me bewondered. Maybe providing a link to a plugin/tutorial/whatever that does this correctly was the actual question.
Marki
Can't you just generate the code, add a select box to the generated view that will post back to the form, creating a filter? Seems pretty straightforward once you get past the idea that this is super complex and needs an existing solution packaged up for it.
Travis Leleu
Ideally, I would want it to generate those select boxes automatically on each index page and for each column that actually represents a foreign key.
Marki
@Marki: I understand that you want to have it automatically, just don't forget, ain't no such thing as a free lunch.
sibidiba
A: 

I think you want this one. The author of the filter wrote:

Filters hasOne and belongsTo relationships (I prefer selects from dropdowns, but to each their own).

bancer
I actually tried to use this one http://github.com/josegonzalez/cakephp-filter-plugin/ (they seem to be related) but it ended with $filter in the view not being known. Apparently these plugins don't work with cake 1.3
Marki
1. Have you included the filter component in your controller (var $components = array('Filter.Filter');)?2. Have you tested it with 1.2?
bancer
I have included it, yes. As to point 2):At http://www.jamesfairhurst.co.uk/posts/view/cakephp_filter_component/ the last comment says: This component and all the forks of this component do not work in cake 1.3 - It looks like they have changed the Controller data structure so $controller->{$key} doesn't match up with anything.I just wouldn't know what to make of it.
Marki
That's clear. CakePHP 1.3 stable version has just recently been released. I don't think you will find better filtering solution now. So, either wait for the fix of that component or make the fix yourself or ask the author(s) to provide the fix or find another solution. :)
bancer
I just upgraded my application to cakephp 1.3. I use this filter in it - http://uplevel.home.pl/cakephp/components/filter.txt. No problems so far noticed. I do not use dropdown lists for filtering but input fields.
bancer