Reputation: 29141
Currently I'm letting my user choose how they want their event to repeat: daily, monthly, weekly, or yearly.
I have these as tinyint(1) fields in my database. So - they're on the page as checkboxes, and I'm using javascript to catch when a user clicks one, and uncheck the rest. No big deal, and is working just fine.
TLDR: I would love to be able to have them in a dropdown instead. Is there a way to convert multiple tinyint(1) fields into a single dropdown? Or will I just need to do it manually (HTML form field not related to a database field), then convert the data when it comes into the controller?
Upvotes: 0
Views: 438
Reputation: 26
You can create a "repeating" table for the event repeating period. The table would have an id and a name field. Then, in your event field, create a repeating_id field. You can now create a model to your repeating table and use standard CakePHP conventions to populate the form by passing the results of a "list" operation on the table into your view.
The more I use CakePHP, the more I find approaching solutions this way much easier to create and maintain.
Upvotes: 1
Reputation: 360792
Convert it to a single ENUM field? repeats enum('daily', 'monthly', 'weekly', 'yearly', 'none')
or somesuch would do the trick.
Upvotes: 0
Reputation: 540
In your controller:
$this->set('fields',Set::extract('/COLUMNS/Field', $this->Model->query("DESCRIBE {$this->Model->useTable}")));
In your view:
$this->Form->input('yourdropdown', array('options' => $fields));
Upvotes: 1