zen of coding

Revisiting saveAll() and HABTM

During my months of winter hibernation, or maybe due to some oversight in prior review of the test cases… I’ve missed a very important and a great feature, which is that saveAll() can also work with HABTM data. Let’s see a quick example based on the provided test cases. We[…]

Read More »

Paginate associated model's data in CakePHP

This is a pretty simple tip, but I’ve noticed some beginners are having a problem with this scenario. We are in the Users Controller and need to paginate all Comments for a given User (i.e. User.id = 5), well and probably display the User info while we are at it…[…]

Read More »

saveAll() with multiple records AND for multiple models

Update (05/23/2011): Ceeram proposed an even easier workaround. And hopefully this will be addressed in an upcoming build of cake: http://cakephp.lighthouseapp.com/projects/42648/tickets/1704-form-helper-keying-not-working-as-expected-in-some-situations#ticket-1704-3 ———— Update (05/12/2011): It appears that in 1.3.x versions of CakePHP form helper doesn’t generate the input name correctly, the workaround is to supply a name key, to override[…]

Read More »

Run multiple CakePHP apps side-by-side

Working with a few different clients? Need to run a couple of apps on the same development server? Tired of dealing with sub directories? (i.e. www.example.com/app1/, www.example.com/app2/) … Well then you’ve stumbled onto the right place. In this quick, introductory how-to, I’ll show you my approach for using a rather[…]

Read More »

Blacklist your model fields for save()…

You’ve probably heard that in order to make your save() more secure, you can pass-in a third parameter of only those fields that you’d like to save (all others will be ignored). However, in some cases it would make more sense to “blacklist” one or two fields, rather than “whitelist”[…]

Read More »
%d bloggers like this: