cakePHP gotchas
Oct 4, 2007
I've been foiled lately by a couple of cakePHP gotchas. Though in general, cake and I get along fine, there are times we just don't see things in the same light. Some situations require you force cake to work the way you need, otherwise your solution just won't work correctly. Here are two things I've found that people should keep in mind when working in cake.Model Query Caching
Apparently, when you're making insertion/update queries to a model, cake caches them and runs all queries at one time. This can create big problems when you need to insert or update a table and rely on that information to be in the database during the next iteration of a loop structure. If you ever notice cake to be doing strange things to your query order, try to set the instance variable $cacheQueries of your model to false. I may have just saved you about an hour of frustration.
Database Cache Files
On top of caching your queries, cake also caches the structure of your database so it doesn't always have to request it every time you load a page. This can be very helpful, but it can also create big problems if it doesn't update when you make any changes to the database structure. I've now made it a habit to delete any of the cache files in /app/tmp/cache/models/ to force cake to reevaluate your database's structure. Again, another hour of frustration saved!
2 commentsBret Kuhns
Oct 27, 2007
Thanks for pointing that out! Those darn typos!






LeanDemon