January 6th, 2011
Since my earlier CakePHP post seemed to help some folks out, I’m back with another Pro-Tip that improves Cake’s handling of paged results. Its built-in pagination functions are nearly ideal except for one glaring problem: the query string is not preserved between pages. This adds unnecessary difficulty when implementing such basic functionality as search results, which often rely on the query string (See: Google).
You may have already picked up the common advice to add the following code to your views:
$paginator->options(array('url' => $this->passedArgs));
Normally the passedArgs here are simply the parameters for the current action, which are part of the current page’s URL. In most cases you want to preserve these, so the code above will do that for you. However, the query string is not preserved, so we need to add a bit of extra code. Luckily the “url” option maps to an array that is processed by the core Router url function. If one of these array keys is “?” then its value (either a string or an array) will be transformed into a query string for the resulting URL. We simply want to include the current query string as it already exists, so we can use a built-in PHP function to do that, then merge it with passedArgs in our final code:
$paginator->options(array('url' => array_merge($this->passedArgs,
array('?' => ltrim(strstr($_SERVER['QUERY_STRING'], '&'), '&')))));
The reason we have to incorporate ltrim and strstr is because CakePHP already processes every page request with a “behind the scenes” query string that contains an initial “url” variable. We don’t need this for our purposes, so we discard it and take the rest of the query string.
Truthfully I feel like this functionality should be nicely integrated into Cake by default, instead of requiring the use of this fix. Perhaps another $paginator option is needed in the view that allows one of three values for URL preservation: the current action only (which is presently the default), the full URL minus the query string, and the full URL including the query string (which I believe should be the default). But until then, I hope this tweak can help you out.
Posted in Web Stuff | 1 Comment
December 9th, 2010
Someday the whole story will be written. But sometimes pictures do say more than words.




Posted in Travels | 6 Comments
September 30th, 2010
It was meant only to remind me of the meat and bean fiesta awaiting me in the company fridge, but a well-meaning coworker’s note—which reads “Take Chili Home!”—has also inspired me with an idea for the next Ben Stiller movie, which capitalizes on his earlier comedic expertise in the arena of man vs animal. Take Chili Home finds Ben Stiller as lonely cab driver Jeff Shakespeare in New York City. One evening a rich socialite (such as Paris Hilton—perhaps played by her?) steps out of a random nightclub and hails Jeff’s taxi. She asks him to drive her small chihuahua “Chili” to her grandpa’s condo across town. After some hesitation, she hands over a wad of cash to Jeff, thus making his decision easier.

Best on-screen duo since Turner and Hooch? Heck yes.
For the next hour, hijinks ensue as Jeff and Chili make their fateful trek. Soon enough Chili jumps out of the window when he sees a cute girl dog and Jeff has to chase him down on foot. (Later hilarity occurs when Chili’s new girlfriend is found to have stowed away.) Jeff also becomes side-tracked when he gets a call from old friend Vinny Knuckles, who seems like a shady character and needs Jeff to deliver a briefcase. Jeff subsequently becomes paranoid that people are following him for the case, but when the inevitable encounter occurs, Chili saves the day by biting the perp’s ankles. Additional laughs unfold when the perp (and Vinny) turn out not to be the mobsters we think they are.
After an hour of such misadventures, Jeff and Chili arrive at the rich grandpa’s condo. But alas, they find that he has tragically died. He was age 99 anyway, so it was expected. Cue funny flashback scene as he is about to enjoy a fancy dinner but falls backward in his chair. Anyway, at this point Jeff realizes Chili can’t be left alone, so he attempts to track down the socialite again. But as he and Chili are walking down a random street, they see a TV news story about how the socialite was thrown in jail for something embarrassing. Cue violin-backed emotional scene where Jeff and Chili realize that after all their adventures, the only thing they have now is each other.
By the way, at some prior point in the movie a certain cute girl (let’s call her Shelly McEntire, as played by Katherine Heigl) notices Jeff and Chili and congratulates him on his cute dog—she works at a convenience store he frequents. Now here at the end, we can wind the movie down in a rom-com dénouement as it is revealed that the stow-away girlfriend dog—who has just recently been rediscovered—is actually owned by this cute convenience store clerk, who had placed a Missing Missy poster (chihuahua version) on her store window. A happy ending ensues for our 4 heroes!
Posted in Stupidity | Comments Off on Take Chili Home!