cakePHP 3.0.7 - 烘焙编辑功能无法在 patchEntity 中执行保存并出现 Marshaller::merge() 错误

cakePHP 3.0.7 - Baked edit function fails to perform save in patchEntity with Marshaller::merge() error

成员 table 上的烘焙编辑功能在保存之前死于 ->patchEntity 内部的异常,并出现以下错误:

Argument 1 passed to Cake\ORM\Marshaller::merge() must implement interface Cake\Datasource\EntityInterface, integer given, called in E:\membership\vendor\cakephp\cakephp\src\ORM\Marshaller.php on line 594 and defined [CORE\src\ORM\Marshaller.php, line 416]

烘焙代码:

public function edit($id = null)
{
    $member = $this->Members->get($id, [
        'contain' => []
    ]);
    if ($this->request->is(['patch', 'post', 'put'])) {
        debug($member);
        debug($this->request->data);
        $member = $this->Members->patchEntity($member, $this->request->data);
        debug($member);
        if ($this->Members->save($member)) {
            $this->Flash->success(__('The member has been saved.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The member could not be saved. Please, try again.'));
        }
    }
    $this->set(compact('member'));
    $this->set('_serialize', ['member']);


    $memberTypes = TableRegistry::get('MemberTypes');
    $query = $memberTypes->find('list');
    $data = $query->toArray();
    $this->set('memberTypes', $data);
}

我添加了三个调试语句。两个就在使用 ->patchEntitiy 之前,第三个就在之后!输出为:

object(App\Model\Entity\Member) {

'id' => (int) 2,
'member_name' => 'Some Name',
'member_address' => 'On Street',
'member_city_state_zip' => 'Some Where, ST 12345',
'member_type' => (int) 2,
'member_first_year' => (int) 1998,
'member_last_paid_year' => (int) 2015,
'member_email' => 'bogus@email.net',
'member_phone' => '975.852.XXXX',
'member_cell' => '975.852.XXXX',
'member_selected' => '1',
'[new]' => false,
'[accessible]' => [
    'member_name' => true,
    'member_address' => true,
    'member_city_state_zip' => true,
    'member_type' => true,
    'member_first_year' => true,
    'member_last_paid_year' => true,
    'member_email' => true,
    'member_phone' => true,
    'member_cell' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Members'

}

[
'id' => '2',
'member_name' => 'Some Name',
'member_address' => 'On Street',
'member_city_state_zip' => 'Some Where, ST 12345',
'member_type' => '2',
'member_first_year' => '1998',
'member_last_paid_year' => '2015',
'member_email' => 'bogus@email.net',
'member_phone' => '975.852.xxxx',
'member_cell' => '975.852.xxxx',
'member_selected' => '1'

]

在我看来,->patchEntity 正在获取一个对象和一个数组,但不知何故没有将正确的内容发送给 Marshaller?任何帮助将不胜感激。

在此先感谢您的帮助。 GLK

此问题源于更改了字段名称及其类型。但是我忘了更改 Entity::$_accessablity 和 Table::$validator 设置以及 Table::$rules.

傻我吧?但我确实希望 cakePHP 3.0.7 确实抛出了一条消息,指出缺少字段问题和验证器测试错误。

无论如何,希望这对其他人有帮助!