ypnos-web / cakephp-datatables

CakePHP3 Plugin for DataTables plug-in for jQuery
MIT License
27 stars 24 forks source link

Ability to modify request query parameters #67

Closed challgren closed 4 years ago

challgren commented 6 years ago

Since CakePHP version 4.0 is going to make the Request object protected, it would be nice to have the option to pass the query parameters ourselves so we can modify them prior to the component running.

Use case

User doesn't understand that % is really a * so I would like to have the option to replace all *'s with %

ypnos-web commented 6 years ago

There is two existing ways of solving this problem:

  1. Use DataTables ajax.data option to have a client-side callback reformat the parameters
  2. Use delegateSearch option and have your ORM Table's finder interpret/reformat the search string

Both have the advantage that the controller doesn't have to deal with it. How the search string is formatted and interpreted is not a matter to the controller but to the client and/or the model.

What do you think about the proposed solutions?

challgren commented 6 years ago

I never thought of those options. But so here's one case where client side would be a bad option. For example since there is no maxLength set a client could potential request length to -1 or a number that would kill the database. Right now none of my tables are publicly facing but once exposed I wouldn't want to give users the option to have a limit greater than one I specify. So for now my solution is to modify the query parameters before the component works on it.

ypnos-web commented 6 years ago

I understand the concern to limit these parameters as when you request a huge amount of records, not only will it be a strain on the database, but also json_encode() can eat up quite some CPU time as well.

Maybe we should have a member query in the component with a setter for it and, if unset, in find() we use the request to set it?