Cakephp 3.0在“添加”操作中不在关联数据模型上保存DATE和TIME

时间:2016-02-26 11:17:54

标签: cakephp cakephp-3.x

我试图在CakePHP中制作某种自定义日历系统。我要做的是添加一个agendascreen_activity模型(其中所有字段已经正确保存)和一个关联模型agendascreen_no_repetitions,它具有id时间,日期和FK指向活动。

我的问题是日期和时间字段无法正确保存

到目前为止,这是我的代码:

在我的add.ctp文件中:

<?= $this->Form->input('agendascreen_no_repetitions.date', ['type' => 'date']) ?>
<?= $this->Form->input('agendascreen_no_repetitions.time', ['type' => 'time']) ?>

在我的控制器中:

public function add()
    {
        $agendascreenActivity = $this->AgendascreenActivities->newEntity();
        if ($this->request->is('post')) {
            $agendascreenActivity = $this->AgendascreenActivities->patchEntity($agendascreenActivity, $this->request->data);
            if ($this->AgendascreenActivities->save($agendascreenActivity)) {

                $this->Flash->success(__('The agendascreen activity has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The agendascreen activity could not be saved. Please, try again.'));
            }
        }
        $agendascreens = $this->AgendascreenActivities->Agendascreens->find('list', ['limit' => 200]);
        $this->set(compact('agendascreenActivity', 'agendascreens'));
        $this->set('_serialize', ['agendascreenActivity']);
    }

MySql数据库字段的数据类型为DATETIME

在CakePHP调试器中,我可以看到所有数据都在POST()中正确发送。

See picture

但是,当我查看结果时,会将agendascreen_no_repetitions记录添加两次null作为日期和时间的值。

See picture

在ndm的评论之后,我检查了数据是否正确地修补了实体。

我注意到timedate内容直接位于agendascreen_no_repetitions对象下。而不是timedate

enter image description here

我尝试了以下内容:

<?= $this->Form->input('agendascreen_no_repetitions[0].date', ['type' => 'date']) ?>
        <?= $this->Form->input('agendascreen_no_repetitions[0].time', ['type' => 'time']) ?>

导致以下结果:

enter image description here

0 个答案:

没有答案