Последний выполненный запрос не будет показан в cake2php с использованием getlog () - PullRequest
0 голосов
/ 14 января 2019

Я пытался получить последний запрос оператора sql, используя функцию getlog из cake2. Обычно я получаю 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");
}

1 Ответ

0 голосов
/ 14 января 2019

Я нашел проблему.

Проблема заключалась в том, что в модели не было beforesave () и aftersave (). Убедитесь, что они оба созданы и возвращают true.

...