1

我对 Cakephp 很陌生'我试图获取发布数据并更新发票表。但是我应该从 post 数据中获取医生 ID 的值,并从医生表和更新发票表中获取与医生 ID 相关的推荐费。

我尝试使用此代码但没有用。请帮帮我。

if ($this->request->is('post')) {

    $this->Invoice->create();
    if ($this->Invoice->save($this->request->data)) {
        $refid = $this->request->data['Invoice']['refid'];  
        print_r($refid);
        $doctor = $this->Doctor->findById($refid);
        $rfee = $doctor['Doctor']['rfee'];
        $invoice_number = $this->request->data['Invoice']['invoice_number'];
        $invoice = $this->Invoice->findByInvoiceNumber($invoice_number);
        $invoice_id = $invoice['Invoice']['id'];
        $this->Invoice->id = $invoice_id;
        $this->Invoice->save('refee', '200');
        $this->Session->setFlash('Invoice Successfully Added');

        $this->redirect(array('controller' => 'invoices', 'action' => 'edit', $invoice_id));
   } else {
       $this->Session->setFlash('Unable To Add Invoice');
   }
}
4

1 回答 1

1

尝试以此更新记录

$this->Invoice->save($this->request->data,false);

如果记录更新成功,则意味着您发布的数据有一些验证规则失败。如果此问题不能通过这种方式解决,请检查发票表的 PK 是否存在于您的 POST 数据中,如果不存在则设置它并重新运行您的代码

于 2013-09-13T11:34:09.030 回答