我尝试使用以下代码,但没有在mssql中工作,并且没有在CakePHP中使用版本2.6生成任何错误消息:
$product_id = $this->request->data['products']['product_id'];
$this->request->data['ProductTbl']['id'] = strtotime(date('Y-m-d H:i:s'));
$this->request->data['ProductTbl']['retailerId'] = $this->request->data['products']['retailer_id'];
$this->request->data['ProductTbl']['productCode'] = $product_id;
$this->request->data['ProductTbl']['productType'] = $this->request->data['products']['product_type'];
//$this->request->data['ProductTbl']['mmGroupId'] = $this->request->data['products']['merchandise_id'];
$this->request->data['ProductTbl']['name'] = $this->request->data['products']['product_name'];
$this->request->data['ProductTbl']['description'] = $this->request->data['products']['product_desp'];
$this->request->data['ProductTbl']['isLayawayable'] = $this->request->data['products']['product_layway'];
$this->request->data['ProductTbl']['isTaxExemptible'] = $this->request->data['products']['product_tax'];
$this->request->data['ProductTbl']['productURL'] = $this->request->data['products']['product_url'];
$this->request->data['ProductTbl']['status'] = 2;
$this->request->data['ProductTbl']['lastModified'] = date('Y-m-d H:i:s');
$this->request->data['ProductTbl']['isDeleted'] = 0;
if(!empty($this->request->data['pjosn'])){
$pjson_arr = $this->request->data['pjosn'];
$this->request->data['ProductTbl']['propertiesJson'] = json_encode($pjson_arr);
}
$this->ProductTbl->save($this->request->data['ProductTbl'],false);
$last_id = $this->ProductTbl->getLastInsertID();
感谢。
答案 0 :(得分:0)
为什么你使用第二个参数' false'在保存功能???
我认为可能的问题应该是第二个论点。我正在使用cakePHP 2.7.5,根据我的保存查询将是::
$res = $this->ProductTbl->save($this->request->data);
if($res){
// do whatever you wants
}
或者第二个问题可能在以下代码中:
if(!empty($this->request->data['pjosn'])){
$pjson_arr = $this->request->data['pjosn'];
$this->request->data['ProductTbl'['propertiesJson']=json_encode($pjson_arr);
}
在json_encode中,您的数据将采用joson格式(例如:{" key1":value1," key2":value2," key3":value3,& #34; key4":value4," key5":value5})cakePHP插入查询不接受。