简体   繁体   English

不能使用类名类型的对象作为数组错误

[英]Cannot use object of type classname as array error

Here is the situation, I'm trying to insert data in a for loop using a model, however, I keep getting an Cannot use object of type App_Model_TogaDesk_RepairOrderFiles as array error.这是这种情况,我正在尝试使用模型在 for 循环中插入数据,但是,我不断收到无法使用 App_Model_TogaDesk_RepairOrderFiles 类型的对象作为数组错误。

Here is the code:这是代码:

    for ($i=0; $i < $countfiles; $i++) {
      $fileNameAct = $files['file']['name'][$i];
      $type = $files['file']['type'][$i];
      $tmp_name = $files['file']['tmp_name'][$i];
      $size = $files['file']['size'][$i];
      $error = $files['file']['error'][$i];
 
      $files = new App_Model_TogaDesk_RepairOrderFiles();
      $files->workorderid = $repairid;
      $files->RevUserFileName = $fileNameAct;
      $files->RevUserFileType = $type;
      $files->RevServerFilePath = $filePath;
      $files->currentVersion = '1';
      $files->personid = $data['personid'];
      $versionid = $files->save();
   }

Even though the data is actually an array, for some reason, it thinks it is an object.尽管数据实际上是一个数组,但出于某种原因,它认为它是一个对象。

I resolved the issue, what happened, I had the array named as the model call.我解决了这个问题,发生了什么,我将数组命名为模型调用。

So I changed the model from所以我改变了模型

  $files = new App_Model_TogaDesk_RepairOrderFiles(); 

to

 $file = new App_Model_TogaDesk_RepairOrderFiles();

That did the trick.这就是诀窍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM