Hey everyone,
I want that to save the Customer (customer_id) multiple times but with different date and menu_item_id.
Example:
Customer: Max | Date: 11.06.2019 | menu_item_id: 1
Same Customer but | Date: 10.06.2019 | menu_item_id: 3
Still Same Customer | Date 09.06.2019 | menu_item_id: 5
This is what i want to do but i cant make it work.
My Orders add.ctp
<div class="customers index large-9 medium-8 columns content">
<?= $this->Form->create($order) ?>
<h3><?= __('Bestellung Tabelle') ?></h3>
<?php
echo $this->Form->control('customer_id', array('label' => __('Kunde', true)),['options' => $customers, 'empty' => false]);
echo $this->Form->control('date', array('label' => __('Datum',true), 'empty' => true));
echo $this->Form->control('menu_item_id', array('label' => __('Menü',true), 'empty' => true));
?>
<?= $this->Form->button(__('Bestätigen')) ?>
<?= $this->Form->end() ?>
I tryed to just add another two of those:
echo $this->Form->control('date', array('label' => __('Datum',true), 'empty' => true));
echo $this->Form->control('menu_item_id', array('label' => __('Menü',true), 'empty' => true));
so I have:
echo $this->Form->control('customer_id', array('label' => __('Kunde', true)),['options' => $customers, 'empty' => false]);
echo $this->Form->control('date', array('label' => __('Datum',true), 'empty' => true));
echo $this->Form->control('menu_item_id', array('label' => __('Menü',true), 'empty' => true));
echo $this->Form->control('date', array('label' => __('Datum',true), 'empty' => true));
echo $this->Form->control('menu_item_id', array('label' => __('Menü',true), 'empty' => true));
but they just overwrite the Inputs I entered before them.
So how can I save the same Customer with multiple Dates and Menus? Because I think i need to change something in my Controller but I am not sure what.
OrdersController.php (only the add function)
public function add()
{
$order = $this->Orders->newEntity();
if ($this->request->is('post')) {
$order = $this->Orders->patchEntity($order, $this->request->getData());
if ($this->Orders->save($order)) {
$this->Flash->success(__('The order has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The order could not be saved. Please, try again.'));
}
$customers = $this->Orders->Customers->find('list', ['limit' => 200]);
$menuItems = $this->Orders->MenuItems->find('list', ['limit' => 200]);
$this->set(compact('order', 'customers', 'menuItems'));
}
I read something about changing the newEntity() to newEntities() but I didnt understood how to do it with my code?
Im pretty new to coding in general only got some knowledge from cms systems, so I would be pretty happy if someone could help me to understood it better.