Cakephp 如何报告非列输入字段的错误

Cakephp 如何报告非列输入字段的错误,cakephp,error-handling,cakephp-3.0,cakephp-3.1,Cakephp,Error Handling,Cakephp 3.0,Cakephp 3.1,我有一个创建一批事件的表单。它有名称、描述、位置、开始和结束时间的输入,所有这些都是events表中的列。它也有许多日期输入,使用字段名,如dates.0.date,dates.1.date,等等 echo $this->Form->input('name'); echo $this->Form->input('description'); echo $this->Form->input('location'); echo $this->Form->

我有一个创建一批事件的表单。它有名称、描述、位置、开始和结束时间的输入,所有这些都是events表中的列。它也有许多日期输入,使用字段名,如
dates.0.date
dates.1.date
,等等

echo $this->Form->input('name');
echo $this->Form->input('description');
echo $this->Form->input('location');
echo $this->Form->input('start');
echo $this->Form->input('end');
for ($i = 0; $i < $this->request->data['repeat_count']; ++ $i) {
    echo $this->Form->input("dates.$i.date", ['type' => 'date']);
}
问题在于提供的日期无效。实体未保存,错误正确定位在
$e->errors('date')
中。但我不知道如何按日期向用户报告该错误。根据并使用其他地方标准的点表示法,我尝试了
$event->errors(“dates.$I.date”、$e->errors(“date”),并确认在呈现视图时实体中的错误列表中保留了任何此类错误(即,如果我使用
debug($event->errors());
)。但是当我创建输入字段时,没有错误日期的错误消息。它们都有提交的值,只是没有错误

尝试使用“date”而不是“dates”作为字段名的基础(例如,
date.0.date
而不是
dates.0.date
),以查看是否由于“dates”不是表中的列而跳过错误检查,但这只会在验证其余数据时导致验证错误,所以我没有进一步追求这个选择


我在其他地方有一些代码设置关联实体上的错误,如果转换为这种情况,这些错误看起来像
$event->dates[0]->errors($e->errors('date')
,但是
$event
与日期无关,所以我不知道如何在这里实现这一点。我尝试在
$event
实体中将
日期创建为数组,但分配
$event['dates'][$I]=$this->Events->newEntity(…)导致PHP警告:“间接修改重载元素无效”,实体被丢弃。可能手动创建一些ArrayContext对象并将错误分配到该对象中?我不知道该怎么做。

太多的信息和太少的信息一样有问题,大多数人都会感到不知所措,不会费心阅读这些内容。因此,除了这面详细的文字墙之外,添加一些控制器/模板代码片段的简短说明(代码方面)将非常有帮助,并且很可能为您提供更好的(任何)答案。感谢@ndm的反馈。我休假了一段时间,同时奖金也没了-(我现在添加了一些代码,希望这有帮助!看起来是相关的。
$event = $this->Events->newEntity(array_merge(
    $this->request->data, ['team_id' => $id, 'dates' => []]));

if (!$this->Events->connection()->transactional(function () use ($id, $event) {
    for ($i = 0; $i < $this->request->data['repeat_count']; ++ $i) {
        // Use $e for the entity that is actually saved, so the
        // $event entity isn't mangled
        $e = $this->Events->newEntity(array_merge(
            $this->request->data,
            [
                'team_id' => $id,
                'date' => $this->request->data['dates'][$i]['date']
            ]
        ));
        $this->Events->save($e);
    }
    if ($event->errors()) {
        $this->Flash->warning(__('The event could not be saved. Please correct the errors below and try again.'));
        return false;
    }
    return false;
})) {
    $this->set(compact('event'));
    return;
}