I have 3 tables:
language (id, name)
action (id, active)
action_items (action_id, language_id, name)
For tables is foreign keys:
action_items.action_id => action.id
action_items.language_id => language.id
I have form:
<?= $this->Form->create($action) ?>
<?php
echo $this->Form->control('active');
echo $this->Form->control('action_items.0.name');
echo $this->Form->control('action_items.language_id._ids', [
'type' => 'select',
'multiple' => true,
'options' => ['1' => 'CZ', '2' => 'EN']
]);
?>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
What I need?
I fill âaction_items.0.nameâ
I select âaction_items.language_id ._idsâ option 1 and 2, after submit form result is:
Result from: $this->request->getData()
[
'active' => '1',
'action_items' => [
(int) 0 => [
'name' => 'test 4'
],
'language_id' => [
'_ids' => [
(int) 0 => '1',
(int) 1 => '2'
]
]
]
]
I would need:
How to save 2 records into the second table action_items if I have selected 2 records from the select?
The patch entity should look like this:
[
'active' => '1',
'action_items' => [
(int) 0 => [
'name' => 'test 4'
'language_id' => 1
],
(int) 1 => [
'name' => 'test 4'
'language_id' => 2
]
]
]
If I do patchentity, it looks like this:
Result from: $this->Action->patchEntity($action, $this->request->getData(), [âassociatedâ => [âActionItemsâ]]);
object(App\Model\Entity\Action) {
'active' => (int) 1,
'action_items' => [
(int) 0 => object(App\Model\Entity\ActionItems) {
'name' => 'test 4',
'[new]' => true,
'[accessible]' => [
'language_id' => true,
'name' => true,
'action' => true,
'language' => true
],
'[dirty]' => [
'name' => true
],
'[original]' => [],
'[virtual]' => [],
'[hasErrors]' => false,
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ActionItems'
},
(int) 1 => object(App\Model\Entity\ActionItems) {
'[new]' => true,
'[accessible]' => [
'language_id' => true,
'name' => true,
'action' => true,
'language' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[hasErrors]' => true,
'[errors]' => [
'name' => [
'_required' => 'This field is required'
]
],
'[invalid]' => [],
'[repository]' => 'ActionItems'
}
],
'[new]' => true,
'[accessible]' => [
'active' => true,
'action_items' => true
],
'[dirty]' => [
'aktivni' => true,
'action_items' => true
],
'[original]' => [],
'[virtual]' => [],
'[hasErrors]' => true,
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Action'
}
Can you help me, please?