dttwois6098 2015-08-06 16:42
浏览 34

一个控制器多个表

I am working on a form that needs to be able to update two different tables. I am using the Order controller and need to update the order table. The other table I need to update is CampaignCustomers, where I would like to update the campaignID.

The two Models are associated, and here is the result when I debug $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
    ),

This is my view:

<?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>";
?>

The only thing that won't update is the CampaignID field, because it is a different table.

Does anyone know how to solve this problem?

Thanks!

  • 写回答

1条回答 默认 最新

  • douzuizhuo0587 2015-08-06 23:48
    关注

    You've not passed the CampaignCustomer data in your form, so when the post request is made, there's nothing for it to update in terms of CampaignCustomer

    You need to include this information in your form in either hidden fields or visible ones to ensure it gets updated.

     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");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大