Hello,
I want save multiple prices for one meal at the same action.
The meals have different prices for the different user groups.
In the form i’ve try.
echo $this->Form->input('meal_id', ['options' => $meals]);
foreach($groups as $group){
echo $this->Form->input('price.'.$group['id'], array(
'label' => $group['name'] . ' '. __('Price'),
'id' => 'price['. $group['id'].']',
'empty' => true,
'style' => 'width:160px;'
));
}
And in the controller I've try this :)
// $i is also the nr of the price[id] from the input field
for ($i = 1; $i <= $max; $i++) {
$price = $this->Prices->patchEntity($price, $this->request->data);
????
}
First try …
Now I try this.
Intentions is. There is only one view for the client in which every price can be add or edit.
in my template
<div class="prices large-9 medium-8 columns content">
<?= $this->Form->create($price) ?>
<fieldset>
<legend><?= __('Prices') ?></legend>
<?php
echo '<table>';
echo '</thead><tr>';
echo '<th>Essen</th>';
foreach($groups as $group){
echo '<th><!-- layout --></th>';
}
echo '</tr></thead>';
echo '<tbody>';
foreach($meals as $meal){
echo '<tr><th>'.$this->Form->hidden($meal['id'], array(
'id' => $meal['id']
)) . $meal['name'].'</th>';
foreach($groups as $group){
echo '<th>';
echo $this->Form->input('price.'.$group['id'], array(
'label' => $group['name'] . ' '. __('Price'),
'id' => 'price['. $group['id'].']',
'empty' => true
));
echo '</th>';
}
echo '</tr>';
}
echo '</tbody></table>';
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
and in the controller I’ve try this now…
$price = $this->Prices->newEntity();
if ($this->request->is('post')) {
return debug($this->request->data);
}
$groups = $this->Prices->Groups->find('all');
$meals = $this->Prices->Meals->find('all');
$prices = $this->Prices->find('all');
$this->set('prices', $prices);
$this->set('meals', $meals);
$this->set('groups', $groups);
$this->set(compact('price'));
but the debug return only… [ (int) 1 => ‘’, ‘price’=>[(int) 1 => ‘’; …]
What is the way to do this?
I’m going to the cellar and drink a beer, now.
Thank you for your help,
Marc