0

There are two tables in our database that are important for this question. In Orders, we have the following fields:

ID, account_id, sale_id, site_id, pending, order_date

The other related table, orders_product_types, is an associative table that contains

order_id, product_id, quantity

Cake originally baked an admin page for orders that works just as you would expect. However, the client has requested that we add the ability to edit the quantity of each product associated with the sale on that same orders.admin_edit page, as well as see the products on the admin_view page. I have already managed to get the view page to display (albeit in an unpretty way) with the following code. To the controller, I added

$order = $this->Order->findById($id);
    $this->recursive = 1;

to the controller and included it in the set, and I display them on the view page with this:

<?php foreach ($order['ProductType'] as $productType){
            echo $productType['type'];
            echo $productType['OrdersProductType']['quantity'];?>
            <br></br>
            <?
        }?>

However, now I'm stuck on how to do this in the cake form for editing. Ideally, I would like to find a way to do this using proper cake functions, but I'm still new to this and am still figuring out how everything works. The pertinent part of the form that allows them to edit the information for the order looks like this:

<?php echo $this->Form->create('Order'); ?>
<fieldset>
    <legend><?php echo __('Edit Order'); ?></legend>
<?php
    echo $this->Form->input('id');
    echo $this->Form->input('account_id');
    echo $this->Form->input('sale_id');
    echo $this->Form->input('site_id');
    echo $this->Form->input('pay later');
    echo $this->Form->input('order_date');
    echo $this->Form->input('Coupon');
    echo $this->Form->input('ProductType');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>

Ideally, I would like to find some way to follow this syntax, but to include fields from the associated table orders_product_types so that they can edit the quantities directly in this form. How would I include a second table within the cake structure?

4

1 回答 1

0

我无法找到一种方法来“正确”地使用我正在寻找的蛋糕语法来做到这一点,但我最终通过在视图中插入一个表格来解决问题,如下所示:

<table>
    <? foreach($productTypes as $id => $productType):?>
    <tr class="product">
        <td><?= $productType ?></td>
        <td class="price" id="<?= $id ?>"></td>
        <td>        
            <select name="data[Quantity][<?=$id?>]" class="quantity">
                <option value="0">0</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
            </select>
        </td>
        <td class="subtotal"></td>
    </tr>
    <? endforeach; ?>
    <tr>
        <td colspan="4" style="text-align: right" id="total"></td>
    </tr>
</table>

如果有人有正确的方法,请告诉我。我还在学习蛋糕的方法,每一点都有帮助。

于 2013-06-18T23:47:22.930 回答