Just another post about the new beforeSave() callback function ;-)

I am sure you have encountered the problem described in the FAQ entry “My Checkbox is not saving to the database record?” when you worked with checkboxes. A solution with beforeSave() allows you to move the corresponding code from the controller to the model because I think the model is the right place for doing such things. Here is the code:

function beforeSave()
{
  $this->data['Event']['public'] =
                                isset($this->data['Event']['public']) ? 1 : 0;
  return true;
}