Reputation: 5454
I have trouble saving my date field into database using CakePHP.
Table column name
[User].[dob]
View
<?php echo $this->Form->input('dob', array('type'=> 'date', 'label' => FALSE, 'dateFormat' => 'DMY', 'minYear' => date('Y') - 111, 'maxYear' => date('Y'))); ?>
I get the following error when I submit the form -
2011-12-29 00:33:57 Debug: Notice (8): Array to string conversion in [C:\xampp\htdocs\dearmemoir\cake\libs\router.php, line 1573]
This field is part of the Auth User Model. Any ideas what might be going wrong?
Upvotes: 3
Views: 3453
Reputation: 5454
This line of code did the magic for me -
$this->data['User']['dob'] = date('Y-m-d', strtotime($this->data['User']['dob']));
I am able to save data now!
Upvotes: 2
Reputation: 12793
I suspect that you are looking in the wrong place. The error message is coming from the CakePHP routing (router.php) - i.e. possibly the redirect URL that you are using.
The example code you give looks correct, it almost exactly matches an example from the Cake cookbook:
echo $this->Form->input('birth_dt', array( 'label' => 'Date of birth', 'dateFormat' => 'DMY', 'minYear' => date('Y') - 70, 'maxYear' => date('Y') - 18 ));
You can add in a check for any validation errors.
Upvotes: 0