0

I have a MySQL table with a field (varchar) with a default value like "#ffffff".

To use this default I know that I can use a snippet like this:

$item_details = $this->request->data;
unset($item_details['Item']['position']);
$this->Item->create();
$this->Item->save($item_details);

... in which unset() and create() are used to reset a field and use the default value.

What I don't understand: I mostly don't work in the Models/Controllers, because I use cake bake for scaffolding (automatically building Models and Controllers) and try to work only on the Views (templates, ctp). How do I implement such a special handling and prevent the overwriting of the code while scaffolding via cake bake? I was searching for a possibility to put this into the config area, but have not found any helpful information about this.

Maybe there's another idea for a solution to use MySQL default values, when the form input field is empty.

(There's said, that scaffolding is only effective in early project states - this is an early project state. :) )

Thanks in advance.

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59
Michael
  • 621
  • 5
  • 17
  • I don't use `bake` a lot, but surely once you've baked your code there is no reason to do this again and hence no reason to overwrite the code? – drmonkeyninja Jun 12 '15 at 10:17
  • Maybe I use CakePHP wrong all the time, but my mostly liked feature is to update the database structure (add fields, tables, reduce redundancy, change types, null/notnull and so an - all this while development) - and then I run a cake bake and have my backend (forms to work with the DB) updated to the new DB structure. – Michael Jun 13 '15 at 10:38

0 Answers0