Useful CakePHP Tutorial Roundup for July 13, 2009
13
Jul
2009
OK, so maybe I’m a few days late. Plenty of useful CakePHP resources out there, just not enough time to write about it all! But, better late than never, right? Anyway, I’m constantly coming across useful tips, code, and tutorials that save me a lot of time. So I thought it might be useful to others to gather up some tutorials every Friday (this is Monday – oops!) and just get them out there. Some are new; some are old chestnuts.
Here’s what I found useful this week:
- Auto Login – Miles Johnson (June 03, 2009)
A useful little component that handles automatically logging in an Auth session if a user checks a “remember me” box during login. Miles just uses a cookie to save the Auth information; it’s not a horribly complex script, but a useful one. Plus, it’s the simplest thing in the world to install: just throw it into your $components array and add the form field to the login view, and bob’s yer uncle.
- Using bindModel to get deep relations – Mark Story (November 14, 2008)
I really like CakePHP, but I think the overuse of queries when fetching related data between models is a glaring weak point. Rather than using LEFT JOINs to retrieve associated data, Cake just executes secondary, tertiary, etc. queries, which is far from optimal in terms of speed, and also means that you can’t apply SQL conditions to the deep relations. So, Mark explains how to use bindModel() and unbindModel() to change model associations on the fly, basically adding custom find conditions in order to execute one big query instead of a bunch of small ones. This is something that really does need to go into the CakePHP core, but for now, solutions such as Mark’s do the job.
- Sitemap Deluxe - Cristian Deluxe (June 15, 2009)
OK, I admit that I haven’t tried this just yet, but Cristian’s sitemap generator looks pretty dang impressive. I’m just getting to the point in my CMS where I need to add a sitemap generator, and in the interests of time I’ll probably try Cristian’s solution. It’s new, so it even includes Bing!
- 8 Ways to Speed Up the Performance of CakePHP Apps – Matt Curry (March 17, 2009)
CakePHP can be a bit slow if you don’t know your way around enough to make the fine tunings necessary to give it a kick in the butt. Fortunately, Mat Curry does know his way around and presented a list of speed-up tips a few months ago. This list eventually made it into his book, which I featured a couple of weeks ago, but this topic is important enough to stand on its own. Not surprisingly, the name of the game here is caching: HTML, view, APC, etc. The one shady suggestion in the list is Matt’s recommendation to use persistant models, which is a buggy feature that tends to break when models have complex associations. Matt does identify this issue in the comments of the post.
- CSV Helper – Adam (ifunk) (September 10, 2007)
Now THIS is an oldie. But it still works, and it works well. Adam – or, should I say, “ifunk” – gave me a real time saver with this admittedly straightforward helper. I’m already using it on one of my side projects to generate CSV files from large sets of data, and it works like a charm with no modification or fixes needed. Usage is really simple, but Adam doesn’t mention that you need to set $this->layout to null and $this->autoLayout to false in the controller method that’ll be doing the exporting. Other than that, it’s a good tutorial. I might also follow the suggestion of a commenter who recommends swapping out the default MIME type of “application/vnd.ms-excel” in favour of the more generic “application/csv”.
And that’s it – see you next Friday.