CakePHP附件组件问题

发布于 2024-11-06 23:57:11 字数 979 浏览 2 评论 0原文

我正在尝试使用附件组件(参见 这里)。我按照说明操作并将其添加到我的视图中:

<?= $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-11-13 23:57:11

嗯,读完组件后...在我看来,您需要像这样调用 upload() 方法:

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

祝你好运!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文