I'm doing 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('Y-m-d', $datestring);
}
There absolutly has to be a better way to do this - I just haven't found the CakePHP way yet...
What I would like to do is:
function add() {
# ... (if we have some submitted data)
$mydatefield = $this->data['Mymodel']['mydatefiled']; # obviously doesn't work
}