cakePHP 3.0.7 - 烘焙编辑功能无法使用Marshaller :: merge()错误

时间:2015-06-26 22:31:35

标签: cakephp cakephp-bake

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

  

传递给Cake \ ORM \ Marshaller :: merge()的参数1必须实现接口Cake \ Datasource \ EntityInterface,给定整数,在E:\ membership \ vendor \ cakephp \ cakephp \ src \ ORM \ Marshaller.php中调用第594行并定义[CORE \ src \ ORM \ Marshaller.php,第416行]

Baked代码:

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

1 个答案:

答案 0 :(得分:0)

此问题源于更改字段名称及其类型。但我忘了更改Entity :: $ _ accessablity和Table :: $ validator设置以及Table :: $规则。

我的愚蠢,是吗?但我确实希望cakePHP 3.0.7实际上抛出一条消息,表明缺少字段问题和验证器测试错误。

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