douqiang4501 2011-05-10 16:35
浏览 45
已采纳

CakePHP附件组件问题

I am trying to use the Attachment component (seen here). I followed the instructions and added this to my view:

<?= $this->Form->create('Event', array('type' => 'file'); ?>
<?= $this->Form->file('image_attach'); ?>

Then added this into my controller's add function:

$this->data['Event']['image'] = $this->Attachment->upload($this->data['Event']['image_attach']);

I also declared this at the top of my controller class:

var $components = array('Attachment' => array(
    'photos_dir' => 'events'
));

When the form is submitted, I have it var_dump'ing my data variable to see what's being added. But before that happens, I get this error.

Notice (8): Undefined index: event [APP/controllers/components/attachment.php, line 67]

I've tried looking in the component's file, and all I can tell is it's trying to find an index that is the name of my model in the array I pass through. But, I already figured that out from the error above.

I just want to know if I've done something wrong, or what might be causing this to happen, whether it's my fault or the component's?

Thanks,

  • 写回答

1条回答 默认 最新

  • douken1726 2011-05-10 17:01
    关注

    hmmm after reading the component... it seems to me that you need to call the upload() method like this:

    $this->Attachment->upload($this->data['Event'],'image_attach');
    

    Good Luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数