I do this in app/views/mymodel/add.ctp :
<?php echo $form->input('Mymodel.mydatefield'); ?>
And then, in app/controllers/mymodel_controller.php :
function add() { # ... (if we have some submitted data) $datestring = $this->data['Mymodel']['mydatefield']['year'] . '-' . $this->data['Mymodel']['mydatefield']['month'] . '-' . $this->data['Mymodel']['mydatefield']['day']; $mydatefield = DateTime::createFromFormat('Ym-d', $datestring); }
Absolutely should be the best way to do this - I haven't found a CakePHP way yet ...
What I would like to do:
function add() { # ... (if we have some submitted data) $mydatefield = $this->data['Mymodel']['mydatefiled']; # obviously doesn't work }
source share