【发布时间】:2012-08-24 08:51:22
【问题描述】:
我正在阅读并尝试申请this article about File Uploads,但出现了问题。据说是这样的:
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$document->upload();
$em->persist($document);
$em->flush();
$this->redirect(...);
}
应该进入Controller,这里是upload函数的定义
public function upload()
{
// the file property can be empty if the field is not required
if (null === $this->file) {
return;
}
// we use the original file name here but you should
// sanitize it at least to avoid any security issues
// move takes the target directory and then the target filename to move to
$this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName());
// set the path property to the filename where you'ved saved the file
$this->path = $this->file->getClientOriginalName();
// clean up the file property as you won't need it anymore
$this->file = null;
}
但是我应该把它放在哪里呢?我在控制器中尝试了调用它的操作并发生错误 - Fatal error: Call to undefined method... 我还尝试将它放在不同的类和文件中,并使用 use 添加其命名空间,但错误仍然存在。
你能告诉我错误在哪里吗? :)
【问题讨论】:
标签: symfony