Cakephp 使用查找后无法编辑数据,但需要get

Cakephp 使用查找后无法编辑数据,但需要get,cakephp,orm,cakephp-3.0,Cakephp,Orm,Cakephp 3.0,我无法通过find命令编辑行表中的数据,因为我得到了一个未知的方法“isNew”。我知道我没有使用get命令来检索数据,但我使用了find命令。返回的数据正确(下面给出的数组),但格式错误。我使用了一个查询,需要转换成一个实体,但我不知道怎么做 我的问题是,如果我需要使用get for edit函数来完成这项工作,那么如何使用get命令在where条件下获取数据 传递给Cake\ORM\Table::patchEntity()的参数1必须是Cake\Datasource\EntityInter

我无法通过find命令编辑行表中的数据,因为我得到了一个未知的方法“isNew”。我知道我没有使用get命令来检索数据,但我使用了find命令。返回的数据正确(下面给出的数组),但格式错误。我使用了一个查询,需要转换成一个实体,但我不知道怎么做

我的问题是,如果我需要使用get for edit函数来完成这项工作,那么如何使用get命令在where条件下获取数据

传递给Cake\ORM\Table::patchEntity()的参数1必须是Cake\Datasource\EntityInterface的实例,给定的Cake\ORM\Query的实例


错误原因是
$lessons
是一个返回5个对象的查询。就好像这是一节课似的叫“保存”是不合逻辑的

一次保存一个实体 如果提交的数据是问题中所示的结构,类似于此的代码将实现您所期望的:

if ($this->request->is(['patch', 'post', 'put'])) {
    $patched = $this->Lessons->patchEntities($lessons, $this->request->data());
    foreach ($patched as $entity) {
        $this->Lessons->save($entity);
    }
}

请注意

是的,这是显而易见的,但解决这个问题并不明显,直到我看到cakephp3没有saveAll
<?php foreach ($lessons as $key => $item):
//foreach ($query3 as $item):
    ?>
    <tr>
        <?php echo $this->Form->hidden($key . '.id', ['label' => '', 'value' => $item->id]) ?>

        <td><?= $item->id ?></td>
        <td><?= $item->lesson_date ?></td>
        <td><?= $item->tutor->first_name . ' ' . $item->tutor->last_name ?></td>

        <td><?= $item->students[0]->first_name . ' ' . $item->students[0]->last_name ?></td>
        <td><?= $item->subject->name ?></td>
        <td><?= $item->tutoring_type->value ?></td>

        <td><?php echo $this->Form->input($key . '.lesson_plan', [
                'label' => '',
                'value' => $item->lesson_plan,
                'style' => 'width: 300px; height:50px;'
            ]) ?></td>
    </tr>
<?php endforeach; ?>
[
    (int) 0 => [
        'id' => '12397',
        'lesson_plan' => 'hello'
    ],
    (int) 1 => [
        'id' => '12408',
        'lesson_plan' => ''
    ],
    (int) 2 => [
        'id' => '14432',
        'lesson_plan' => ''
    ],
    (int) 3 => [
        'id' => '12419',
        'lesson_plan' => ''
    ],
    (int) 4 => [
        'id' => '12441',
        'lesson_plan' => ''
    ]
]  
if ($this->request->is(['patch', 'post', 'put'])) {
    $patched = $this->Lessons->patchEntities($lessons, $this->request->data());
    foreach ($patched as $entity) {
        $this->Lessons->save($entity);
    }
}