cakephp: 3.0 - Define request query value if the result is null
Hello, I just have a convenience suggestion. Frequently we have to handle request queries. It often becomes a bother to check if the return value is null, and then define a default value for it with empty() or === null, or something like that. Symfony handles this really nicely by simply being able to pass a second parameter to the query function, as so:
$limit = $this->request->query('limit', 20);
This would essentially return 20 if limit was not given as a request query parameter, thereby making the code more readable, and programming faster. It also wouldn’t break code written in older versions, as if a second parameter is not given, it just returns null as it does now.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 39 (39 by maintainers)
Other frameworks have an own object for each part, e.g. query:
This makes a simple and speaking API without the need for any complexity.
Having separate objects for each part of the request sounds good to me. Wil improve flexiblity of the API, while keeping it simple.
I can see how having defaults for both data() and query() could be useful. I’m not sure param() should support defaults though. That seems like a place where you’d want to error out instead of provide fallbacks.