Cakephp查询无法更新

时间:2013-09-13 11:10:33

标签: php mysql sql cakephp

我对Cakephp很新 我试图获取发布数据并更新发票表。但是我应该从发布数据中获得医生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');
   }
}

1 个答案:

答案 0 :(得分:1)

尝试通过此

更新记录
$this->Invoice->save($this->request->data,false);

如果记录更新成功,那么它的意思是有一些关于您发布的数据的验证规则失败。如果这个问题没有通过这种方式解决,那么检查你的POST数据中是否存在发票表的PK,然后再设置它&重新运行您的代码