我正在处理一个需要能够更新两个不同表的表单。 我正在使用Order控制器,需要更新订单表。我需要更新的另一个表是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字段,因为它是一个不同的表。
有谁知道如何解决这个问题?
谢谢!
答案 0 :(得分: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");