最后执行的查询不会使用 getlog() 在 cake2php 中显示

Last Query Executed would not show in cake2php using getlog()

我尝试使用 cake2 的 getlog 函数获取 sql 语句的最后一个查询。我通常会得到的是 sql 查询,但我得到的是:

$sample: array(3)
  0: array(5)
      query: "Commit"
      params : array(0)
      affected : false 
      numRows : false
      took : false

我试图通过取消设置一些数组数据来匹配数据库中输入的数据,但它仍然得到如上所述的输出。有谁知道如何从保存功能中获取 sql 查询?提前致谢

这是代码:

 public function mod_edit_confirm() {
    $data = $this->Session->read('data_product_edit');

    $title = 'Product Edit Confirmation';
    $button = 'Update';
    $link = '/products/edit/'.$data['MstProduct']['id'];
    $product_type = $this->MstProductType->findById($data['MstProduct']['product_type_id']);
    if(isset($data['MstProduct']['sales_price']) && $data['MstProduct']['sales_price'] != ''){
        $data['MstProduct']['sales_price'] = number_format($data['MstProduct']['sales_price']);
    }
    if(isset($data['MstProduct']['adjustment_of_amount_of_tax_exclusive']) && $data['MstProduct']['adjustment_of_amount_of_tax_exclusive'] != ''){
        $data['MstProduct']['adjustment_of_amount_of_tax_exclusive'] = number_format($data['MstProduct']['adjustment_of_amount_of_tax_exclusive']);
    }
    if(isset($data['MstProduct']['price_of_option_or_goods']) && $data['MstProduct']['price_of_option_or_goods'] != ''){
        $data['MstProduct']['price_of_option_or_goods'] = number_format($data['MstProduct']['price_of_option_or_goods']);
    }
    if(isset($data['MstProduct']['display_price_without_tax']) && $data['MstProduct']['display_price_without_tax'] != ''){
        $data['MstProduct']['display_price_without_tax'] = number_format($data['MstProduct']['display_price_without_tax']);
    }
    if(isset($data['MstProduct']['amount_of_charge_points']) && $data['MstProduct']['amount_of_charge_points'] != ''){
        $data['MstProduct']['amount_of_charge_points'] = number_format($data['MstProduct']['amount_of_charge_points']);
    }
    if(isset($data['MstProduct']['amount_of_bonus_points']) && $data['MstProduct']['amount_of_bonus_points'] != ''){
        $data['MstProduct']['amount_of_bonus_points'] = number_format($data['MstProduct']['amount_of_bonus_points']);
    }

    $category = $this->Category->findById($data['MstProduct']['category_id']);

    if ($this->request->is('post')) {
        //click register product
        if (isset($this->request->data['Save'])) {
            $data = $this->Session->read('data_product_edit');
            if ($data['MstProduct']['color_1'] != '')
                $data['MstProduct']['color_1'] = trim($data['MstProduct']['color_1'],"#");

            if ($data['MstProduct']['color_2'] != '')
                $data['MstProduct']['color_2'] = trim($data['MstProduct']['color_2'],"#");

            unset($data['MstProduct']['end_radio']);
            unset($data['MstProduct']['start_radio']);
            unset($data['MstProduct']['category1']);
            unset($data['MstProduct']['category2']);
            unset($data['MstProduct']['category3']);
            unset($data['MstProduct']['category4']);
            unset($data['MstProduct']['category5']);
            unset($data['Confirm']);
            $this->MstProduct->id = $data['MstProduct']['id'];
            if ($this->MstProduct->save($data)) {
                // here is where i get my datalogs
                $sample=$this->MstProduct->getDataSource()->getLog(false, false);
                $this->Session->delete('data_product_edit');
                if ($data['MstProduct']['product_type_id'] == 1) {
                    $this->MstProduct->saveField('amount_of_charge_points', '');
                } else if ($data['MstProduct']['product_type_id'] == 2) {
                    $this->MstProduct->saveField('treatment_minutes', '');
                } else {
                    $this->MstProduct->saveField('treatment_minutes', '');
                    $this->MstProduct->saveField('amount_of_charge_points', '');
                }
                $this->Flash->success(__d('admin', 'Successfully Updated.'));
                return $this->redirect('/products/edit/complete');
            } else {
                $this->Flash->error(__d('admin', 'Updated Faild.'));
                return $this->redirect('/products/edit/'.$data['MstProduct']['id']);
            }
        } else if (isset($this->request->data['Cancel'])) {
            $this->Session->delete('data_product_edit');
            return $this->redirect('/products');
        }
    }
    $this->set(compact('data', 'product_type', 'title', 'link', 'category', 'button'));
    $this->render("mod_add_confirm");
}

我发现了问题。

问题是我在模型中没有 before save() 和 aftershave()。确保它们都已创建并且 returns 为真。