CakePHP不会在live server上存储创建的日期

CakePHP不会在live server上存储创建的日期,cakephp,cakephp-2.3,Cakephp,Cakephp 2.3,我在本地主机和live server上运行完全相同的脚本和数据库。我面临的问题是“创建”的日期不会自动存储 以下是控制器操作: function add() { if (!empty($this->data) ) { $this->Customer->create(); if ($this->Customer->save($this->data)) { $this->Session->

我在本地主机和live server上运行完全相同的脚本和数据库。我面临的问题是“创建”的日期不会自动存储

以下是控制器操作:

function add() {
    if (!empty($this->data) ) {
        $this->Customer->create();
        if ($this->Customer->save($this->data)) {
            $this->Session->setFlash(__('Customer was saved'), 'positive_notification');
            $this->redirect(array('controller'=>'customers', 'action' => 'index'));
        } else {
            $this->Session->setFlash(__('Customer was not saved. Please try again'), 'negative_notification');
        }
    }
}
beforeSave也没有函数

这是数据库表:

`customers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` int(11) NOT NULL,
  `customer_nr` varchar(20) DEFAULT NULL,
  `name` varchar(60) DEFAULT NULL,
  `address` varchar(250) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `phone` varchar(18) DEFAULT NULL,
  `post_nr` varchar(6) DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL,
  `color` varchar(7) NOT NULL,
  `created` date DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `company_id` (`company_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=113 ;
非常感谢您的帮助。

我认为您必须使用:

     $this->request->data //instead of $this->data
但是,如果创建的是唯一未保存的字段,请首先尝试调试$this->data,然后尝试此操作以查看是否确实保存了数据:

   $this->data["Customer"]["created"] = data("Y-m-d"); // temporarily set to current date just to see if it was saving
   $this->Customer->save($this->data)

然后检查它是否已添加到数据库中。如果是,则必须更新$this->data,它可能包含不正确的值不正确的日期格式

日期不会自动更新,因为您将
创建的
设置为
日期

如“”所述

通过将数据库表中创建和/或修改的字段定义为datetime字段(默认为null),CakePHP将识别这些字段,并在创建记录或将记录保存到数据库时自动填充这些字段(除非保存的数据已经包含这些字段的值)


我希望这能解决您的问题。

尝试将创建的
从'date'更改为'datetime',但运气不佳。您的示例代码不完整!您有模型之间的关系,并且您试图将数据保存到不同的表?很抱歉,客户模型中没有beforeSave功能。所以代码被更新了,我把它改成了datetime。现在,我必须使用完全相同的数据库运行完全相同的脚本,但其中一个只会更改创建日期。