1

我正在处理一个需要能够更新两个不同表的表单。我正在使用订单控制器,需要更新订单表。我需要更新的另一个表是 CampaignCustomers,我想在其中更新campaignID。

这两个模型是关联的,这是我调试 $order 时的结果:

array(
    'Order' => array(
        'OrderID' => (int) 1574996,
        'OrderType' => '3',
        'UPSTrackingNumber' => null,
        'CreatedDate' => 'Mar 30 2019 12:42:00:000PM',
        'ShippedOnDate' => null,
        'Notes' => null,
        'OrderedBy' => 'TIM',
        'UserID' => (int) 431,
        'CampaignCustomerID' => (float) 78156512,
        'TaxPercentage' => (int) 0,
        'DiscountID' => null,
        'DiscountPercentage' => (int) 8,
        'TotalPrice' => (float) 7.75,
        'OrderStatusID' => (int) 13,
        'LabelCategory' => null,
        'LabelPrinted' => (int) 0,
        'InvoicePrinted' => (int) 0,
        'ShippingMethodID' => (int) 9,
        'SaturdayDelivery' => (int) 0,
        'ShippingAddress' => 'ert',
        'ShippingPrice' => (float) 7.75,
        'ConfirmationEmail' => null,
        'PaymentMethod' => 'Bill In Full',
        'PurchaseOrderNumber' => ' dfqsdfsdafe3r23rwererewrw',
        'CreditCardHolderName' => null,
        'CreditCardNumber' => null,
        'CreditCardExpirationDate' => null,
        'CreditCardStreet' => null,
        'CreditCardZipCode' => null,
        'CreditCardCVV' => null,
        'TransactionID' => null
    ),

    'CampaignCustomer' => array(
        'CampaignCustomerID' => (float) 78156512,
        'CampaignID' => (int) 422,
        'CustomerID' => (int) 3633
    ),

这是我的看法:

<?php
debug($order);
echo $this->Html->div("box");
    echo $this->Html->tag("h3","Edit Order ".$order['Order']['OrderID']);
        echo "<p><b>Company: </b>" . $order["Company"]["CompanyName"] . "</p>";
        echo "<p><b>Order ID: </b>" . $order["Order"]["OrderID"] . "</p>";
    echo $this->Form->create(("Order"));
            echo $this->Form->input("PurchaseOrderNumber");
            echo $this->Form->input("CampaignID",array("options"=>$campaigns,"label"=>"Campaign","selected"=>$order["Campaign"]["CampaignID"]));
            echo $this->Form->input("CreatedDate");
            echo $this->Form->input("OrderType",array("options"=>$orderType,"selected"=>$order["Order"]["OrderType"]));
            echo $this->Form->input("OrderedBy");
            echo $this->Form->input("ShippingMethodID",array("options"=>$shipping_method_ids,"selected"=>$order["Order"]["ShippingMethodID"],"label"=>"Shipping Method"));
            echo $this->Form->input("SaturdayDelivery");
            echo $this->Form->input("UserID",array("options"=>$users,"selected"=>$order["Order"]["UserID"],"label"=>"Sales Agent"));
            echo $this->Form->input("DiscountPercentage");
            echo $this->Form->input("ShippingAddress");
    echo $this->Form->end("Update Order");
echo "</div>";
?>

唯一不会更新的是 CampaignID 字段,因为它是一个不同的表。

有谁知道如何解决这个问题?

谢谢!

4

1 回答 1

0

您还没有CampaignCustomer在表单中传递数据,因此在发出发布请求时,它没有什么可以更新的CampaignCustomer

您需要将此信息包含在表单中的隐藏字段或可见字段中,以确保其得到更新。

 echo $this->Form->create();
        echo $this->Form->input("Order.PurchaseOrderNumber");
        echo $this->Form->input("Order.CampaignID",array("options"=>$campaigns,"label"=>"Campaign","selected"=>$order["Campaign"]["CampaignID"]));
        echo $this->Form->input("Order.CreatedDate");
        echo $this->Form->input("Order.rderType",array("options"=>$orderType,"selected"=>$order["Order"]["OrderType"]));
        echo $this->Form->input("Order.OrderedBy");
        echo $this->Form->input("Order.ShippingMethodID",array("options"=>$shipping_method_ids,"selected"=>$order["Order"]["ShippingMethodID"],"label"=>"Shipping Method"));
        echo $this->Form->input("Order.SaturdayDelivery");
        echo $this->Form->input("Order.UserID",array("options"=>$users,"selected"=>$order["Order"]["UserID"],"label"=>"Sales Agent"));
        echo $this->Form->input("Order.DiscountPercentage");
        echo $this->Form->input("Order.ShippingAddress");
        echo $this->Form->input("CampaignCustomer.CampaignCustomerID");
        echo $this->Form->input("CampaignCustomer.CampaignID");
        echo $this->Form->input("CampaignCustomer.CustomerID");
 echo $this->Form->end("Update Order");
于 2015-08-06T23:48:14.913 回答