Cake CleanUpFields

Yesterday night I managed to get stuck on my cake project it two separate places, which is sort of amazing since I have only been stuck with cake once other than that on this project. (To Be fair, One of the problems is with Plesk, may it’s name be damn for a thousand years, not cake)

Anyway, I just solved the other problem thanks to the comments on this post, and I thought I would share.

When you cuse cake’s helper to pick a date/time it builds a whole lot of sub-fields. Then when cleanUpFields is called it stitches them all back together into one date time. However, it’s a little too smart for its own good, it only stitches them back together if it knows about the date-time, and it only knows about the date-time if that field is in the primary model for the controller your working with. This means that if you are using a second model , it wont fix the date-times.

The good news is that their is a work-around for that, you can simply call cleanUpFields again, with the second, or third model name as a param. (I.E. $this->cleanUpFields(‘payments’); )

What I haven’t found a work around for however, is if you want to get a date that doesn’t belong to a model at all. hopefully I will stumble on an answer as I continue with this, If I do I’ll post it in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *