2

我正在尝试按照Symfony 2.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 三个变量

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;
}

我误解了吗?

4

0 回答 0