当前位置: 动力学知识库 > 问答 > 编程问答 >

php - CakePHP Attachment component problem

问题描述:

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,

网友答案:

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!

分享给朋友:
您可能感兴趣的文章:
随机阅读: