一次创建并保存三个相关表 cakephp 3.7

Create and save three related tables at once cakephp 3.7

在志愿者的添加视图中,我有 3 个 table 的表格。 在注册时,我在 People table 中的 'contact_id' 字段有问题。 它们创建正确,但我无法在联系人 table 中创建新表单,因此 cantacto_id 字段不同。 如何同时保存 3 tables?

在您的表单中,有这样的字段:

echo $this->Form->input('direccion');
echo $this->Form->input('persona.nombre');
echo $this->Form->input('persona.voluntario.cv');

在你的志愿者控制器中,有这样的代码:

if ($this->request->is(['patch', 'post', 'put'])) {
    $contact_table = TableRegistry::get('Contactos');
    $contact = $contact_table->patchEntity($contact, $this->request->data, [
        'associated' => ['Personas' => ['Voluntarios']]
    ]);
    if ($contact_table->save($contact)) {
        // etc.