CakePHP附件组件问题
我正在尝试使用附件组件(参见 这里)。我按照说明操作并将其添加到我的视图中:
<?= $this->Form->create('Event', array('type' => 'file'); ?>
<?= $this->Form->file('image_attach'); ?>
然后将其添加到我的控制器的 add
函数中:
$this->data['Event']['image'] = $this->Attachment->upload($this->data['Event']['image_attach']);
我还在控制器类的顶部声明了它:
var $components = array('Attachment' => array(
'photos_dir' => 'events'
));
提交表单时,我有它 var_dump
'ing 我的 data
变量以查看添加的内容。但在此之前,我收到此错误。
Notice (8): Undefined index: event [APP/controllers/components/attachment.php, line 67]
我尝试查看组件的文件,我所能知道的就是它试图在我传递的数组中找到一个索引,该索引是我的模型的名称。但是,我已经从上面的错误中弄清楚了这一点。
我只是想知道我是否做错了什么,或者是什么导致了这种情况的发生,是我的错还是组件的错?
谢谢,
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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,读完组件后...在我看来,您需要像这样调用
upload()
方法:祝你好运!
hmmm after reading the component... it seems to me that you need to call the
upload()
method like this:Good Luck!