当一切都好的时候,保存在cakeph中不起作用

时间:2016-05-16 11:55:37

标签: cakephp

我的代码:

 $this->PackageCustomer->id = $customer_id;
 $data['PackageCustomer'] = array(
     'shipment' => 2,
     'comments' => $this->request->data['Ticket']['content'],
     'shipment_equipment' => $this->request->data['Ticket']['shipment_equipment'],
     'shipment_note' => $this->request->data['Ticket']['shipment_note'],
     'issue_id' => $this->request->data['Ticket']['issue_id']
     );
     pr($data); exit;
     $this->PackageCustomer->save($data['PackageCustomer']);
     //var_dump($this->PackageCustomer->invalidFields());
     //  pr($this->PackageCustomer->error);
     echo $this->PackageCustomer->getLastQuery(); exit; 

我检查数组$ data。数据正在恢复正常。而getLastQuery函数是:

function getLastQuery() {
   $dbo = $this->getDatasource();
   $logs = $dbo->getLog();
   $lastLog = end($logs['log']);
   return $lastLog['query'];
 }

在appModel中定义了哪个。我正在使用cakephp 2.6.9。但最后一个查询是:COMMIT没有任何意义。我检查我的模型惯例。没关系。现在我的代码中出现了什么问题?

1 个答案:

答案 0 :(得分:0)

试试这个::

$this->PackageCustomer->id = $customer_id;
 $data['PackageCustomer'] = array(
     'shipment' => 2,
     'comments' => $this->request->data['Ticket']['content'],
     'shipment_equipment' => $this->request->data['Ticket']['shipment_equipment'],
     'shipment_note' => $this->request->data['Ticket']['shipment_note'],
     'issue_id' => $this->request->data['Ticket']['issue_id']
     );
     pr($data); exit;
     $this->loadModel('PackageCustomer');
     $this->PackageCustomer->save($data['PackageCustomer']);
     //var_dump($this->PackageCustomer->invalidFields());
     //  pr($this->PackageCustomer->error);
     echo $this->PackageCustomer->getLastQuery(); exit; 

如果上述代码不起作用,我需要以下答案以帮助进一步...

我需要更多信息才能确认以下内容:

  • 您要保存的表的名称是什么?
  • 与您要保存的表相关的类的名称是什么?
  • 您是否尝试在此表格中修改或创建新记录?