There’s a quote that you often see in the #cakephp channel on irc.freenode.net and it goes something like, “If something is hard in CakePHP, then you’re doing it wrong”. This is proven to me over and over the more comfortable I get with CakePHP. One of the most annoying problems I had as a Cake newbie was a pretty common scenario:
I’m using Cake’s Paginator component and helper to paginate results from my profiles table. Here, sweet Jesus, is a perfect example of why I love Cake! Pagination used to be such a pain in the ass! Now that I’ve got that working I need to set up some forms so that the results can be filtered. So I write up my filter criteria form using the Form helper (*squeal* *gush*). Say I want a filter on the ‘city’ and ‘name’ fields. Also, because I want to be able to bookmark these customized results, I’m going to use the get method for my form. I set my controller action to parse the form input as usual ($this->data).
Everything looks good to me at this point so I submit the form. Ok, it works. But the URL looks like /profiles/search?name=joe&city=toronto, which looks kinda ugly. Oh, and crap, now my pagination is broken. At this point I come up with various hacks that sorta work, but they’re all terrible. Maybe I’ll rewrite some portions of the Paginator helper, or create my own version because holy shit how did these Cake guys make such a glaring mistake! The stupid Paginator helper uses named parameters but I need to submit my form via get so that I can bookmark the results! Come to think of it, what the hell are these named parameters good for in the first place? Much frustration ensues.