I ran into an issue trying to save a datetime field and I haven't been able
to figure out why it's not saving (not failing).
Database set up is Ubuntu Server 12.04 LTS w/ Percona Server 5.6 -- I'm
using Cake 2.4.1
//table set up
DROP TABLE IF EXISTS `news`;
CREATE TABLE `news` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`title` tinytext NOT NULL,
`article` text NOT NULL,
`start` datetime NOT NULL,
`stop` datetime NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=latin1;
Before saving I convert user input into a savable format. I tried the
conversion in both controller and model beforeSave.
// conversion
$xstart = explode('-', $this->request->data['News']['start']);
$start = strtotime($xstart[0].' '.$xstart[1]);
$date = date('Y-m-d H:i:s', $start);
$this->request->data['News']['start'] = $date;
$xstop = explode('-', $this->request->data['News']['stop']);
$stop = strtotime($xstop[0].' '.$xstop[1]);
$expire = date('Y-m-d H:i:s', $stop);
$this->request->data['News']['stop'] = $expire;
// debug request data
array(
'News' => array(
'start' => '2013-10-21 13:13:00',
'stop' => '2013-10-22 21:00:00',
'title' => 'Test Article Title',
'article' => 'Test Article Body',
'user_id' => '5'
)
)
The request does not fail but it also does not save to DB.
// To test what's happening bypass conversion and throw together quick data
array
$this->request->data = array(
'News' => array(
'title' => 'this is a title',
'article' => 'this is an article',
'start' => '2013-10-22 13:00:00',
//'stop' => '2013-10-22 13:00:00',
));
Data saves fine as long as 'stop' key is not in the array. As soon as I include
the key, nothing saves (I changed the column name a few times thinking perhaps
there was an issue with the name but it didn't help).
If I change the array to use converted data, ie. 'start' => $date it will not
save. Tried casting $date as string, it didn't help.
So, using either formatted date from converted data will not save. My test
array saves as long as I don't include the 'stop' key or try to include
converted data.
I checked all my error logs but there is nothing there. I was sure I'm
overlooking something simple but I just don't see it.
I'm stumped (or perhaps more frustrated at this point).
Any help is appreciated.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.