アップロードを処理するために Symfony 2.1のドキュメントに従おうとしていますが、コード内の変数の 1 つがどこから来ているのか混乱しています。
$this->file 変数はアップロード方法のどこから来るのですか?
Symfony のアップロード方法:
public function upload()
{
// the file property can be empty if the field is not required
if (null === $this->file) {
return;
}
// 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've saved the file
$this->path = $this->file->getClientOriginalName();
// clean up the file property as you won't need it anymore
$this->file = null;
}
ドキュメントの前半で説明した Document エンティティには、id、name、path の 3 つの変数しかないためです。
Symfony エンティティ:
/**
* @ORM\Entity
*/
class Document
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
*/
public $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
public $path;
}
私は誤解しましたか?