0
this article about File Uploads을 읽고 적용하려고했지만 문제가 있습니다.업로드 기능을 어디에 두어야합니까 - Symfony2
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$document->upload();
$em->persist($document);
$em->flush();
$this->redirect(...);
}
가 컨트롤러에 가야하고 여기에 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...
다른 클래스와 파일에 넣고 사용하여 네임 스페이스를 추가하려고했지만 오류가 계속 발생한다. 실수가 어디 있는지 알려주세요. 이 어디로 가야
$document->upload();
그래서, 당신의 문서 엔티티 클래스에있다 : 당신이 코드를주의 깊게 보면 :
때로는 내가 더 바보가 될 수 있는지 궁금합니다 ... 정말 고마워요! – Faery