There are two main methods for finding random records with PHP (and in this case CakePHP) and MySQL: Use a SELECT query with ORDER BY RAND() and LIMIT x (where x is the number of results you want). Get a list of the primary keys of every record in the table, use PHP to select [...]
If you use CakePHP’s caching system but don’t like having to wrap you calls to Model::find() in if statements (“if cache result found… else…”) then this little quick tip is for you. Basically, we’re just going to put a slightly modified version of Model::find() in AppModel. Our new find() method will check for the existence [...]
Most people who do serious, large scale development with CakePHP would agree that keeping the bulk of a project’s code segregated in plugins is the best way to keep things organized. Sometimes, however, we want to use a plugin’s functionality outside of the scope of that plugin’s controllers. For example, we might have a products [...]
Wow! It’s been a while since I’ve written much about CakePHP, PHP, or just anything useful in general. I guess I’ve been pretty busy. Hectic job, baby on the way, that sort of thing. But I’m trying to get back into blogging because it’s a good outlet for my desire to write, plus I love [...]
Just a quick bit of advice to those who may have been banging their heads against the walls when trying to pass “form” as a custom parameter in a CakePHP URL. Apparently ‘form’ is a param – an array, to be specific – that’s already set by Cake and using it as a custom parameter [...]
If you develop in PHP5 and you use Security::cipher in your CakePHP application – which is unlikely, since it’s an obscure function really only used by CookieComponent – and you also use PHP functions like rand() and array_rand(), you might notice an annoying bug: you’re getting the same random numbers each time. This is due [...]
Back on time. I think I’m going to downgrade from a firm 5 tutorials per week to just as many as I have time to review, because I don’t want to skim over material or choose sub-par stuff simply to make my quota. So, three this week. But as always, I’m constantly coming across useful [...]
Apparently custom prefixes and custom named arguments in URLs don’t mix all that well in good ol’ CakePHP. I’ve got a StatisticsController with some custom_-prefixed actions. So, in routes.php I added this line to parse the URLs: Router::connect('/statistics/custom/:action/*', array('prefix' => 'custom', 'controller' => 'statistics', 'custom' => true)); Straightforward enough, right? And to generate a link [...]
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 [...]
Nothing like writing a tutorial on your code to realize how you could improve it! Just minutes after writing a tutorial on persisting pagination limits in CakePHP – a system I developed weeks ago, I wondered to myself why I just didn’t make it a component and boost its portability by a billion percent. So, [...]