0

我正在尝试插入以下数组

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

我错过了什么?谢谢

4

2 回答 2

1

首先,您可以确定在 CallcenterBillingsController 中使用了 CallcenterBilling 模型: public $uses = array('CallcenterBilling');

其次,您可以通过不循环保存来优化它:请参阅模型的saveAll方法

所以你会得到类似的东西:

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);
  }

}

附言。如果这没有帮助,请显示控制器代码。

于 2011-11-07T16:25:26.383 回答
-1

你应该实现这个:

$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();

这可能对你有用。

于 2011-11-07T05:24:04.593 回答