CakePHP中保存数据是给我一个错误

我试图插入下面的数组

foreach($list as $l) { $data = array( 'source_number'=> $l['Csv']['Source'], 'destination_number'=> $l['Csv']['Destination'], 'seconds'=> $l['Csv']['Seconds'], 'callerID'=> $l['Csv']['CallerID'], 'disposition'=> $l['Csv']['Disposition'], 'cost'=> $l['Csv']['Cost'], 'billing_cost'=> $l['Csv']['newCost'] ); //$total[] = $l['Csv']['newCost']; debug($data); $this->CallcenterBilling->save($data); unset($data); }

但潜我这个错误

( ! ) Fatal error: Call to a member function save() on a non-object in C:\wamp\www\wadic\app\Controller\CallcenterBillingsController.php on line 61 Call Stack # Time Memory Function Location 1 0.0005 708160 {main}( ) ..\index.php:0 2 0.0169 2775744 Dispatcher->dispatch( ) ..\index.php:96 3 0.0279 3946176 Dispatcher->_invoke( ) ..\Dispatcher.php:89 4 0.0293 4016984 Controller->invokeAction( ) ..\Dispatcher.php:107 5 0.0293 4017992 ReflectionMethod->invokeArgs( ) ..\Controller.php:473 6 0.0293 4018024 CallcenterBillingsController->import( ) ..\CallcenterBillingsController.php:0

我缺少什么? 谢谢

--------------解决方案-------------

首先,你可以肯定,在CallcenterBillingsController你CallcenterBilling模型的用途: 公共$使用=阵列('CallcenterBilling');

二级您可以通过在循环不节能优化这个:看到模型的白水回收方法

所以你会得到这样的:

class CallcenterBillingController extends AppController {

public $uses = array('CallcenterBilling');

public function someaction() {

$data = array();
foreach ($list as $l) {

$data[] = array(
'source_number' => $l['Csv']['Source'],
'destination_number' => $l['Csv']['Destination'],
'seconds' => $l['Csv']['Seconds'],
'callerID' => $l['Csv']['CallerID'],
'disposition' => $l['Csv']['Disposition'],
'cost' => $l['Csv']['Cost'],
'billing_cost' => $l['Csv']['newCost']
);
//$total[] = $l['Csv']['newCost'];

}
debug($data);
$this->CallcenterBilling->saveAll($data);
}

}

PS。 如果这不是帮助,请出示控制器代码。

您应该实现这一点:

$this->CallcenterBilling->read(null, 1);
$this->CallcenterBilling->set(array(
'source_number'=> $l['Csv']['Source'],
'destination_number'=> $l['Csv']['Destination'],
'seconds'=> $l['Csv']['Seconds'],
'callerID'=> $l['Csv']['CallerID'],
'disposition'=> $l['Csv']['Disposition'],
'cost'=> $l['Csv']['Cost'],
'billing_cost'=> $l['Csv']['newCost']
));
$this->CallcenterBilling->save();

这可能为你工作。

分类:CakePHP的 时间:2015-03-14 人气:0
本文关键词: CakePHP的,CakePHP的2.0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.811 (s). 10 q(s)