定义另一个实体属性时如何使用实体属性

时间:2019-04-23 20:37:46

标签: php doctrine-orm symfony4

我需要使用一个实体中的属性来设置同一实体中另一个属性的值。

让我自己解释一下,我有两个属性,其中之一是图像名称,另一个是下载链接,为了获得下载链接,我需要获取图像名称并将其传递给函数可以从网络上获取我的下载链接

我一直在研究该学说的生命周期方法,但是我无法使其正常工作,此刻我只想将该图像名称放入“下载链接”属性中。

因此,用户上传了一个文件,我得到了文件名,然后取了这个名字,并用它来获取我的下载链接属性中的下载链接。

我再次使用“ PostPersist”方法,当我查看数据库时,它只是返回一个空值

实体:

/**
 * @ORM\Column(type="text", nullable=true)
 */
private $downloadImage;

//I commented out the setters and getters, cause i dont think i  
//need them since i will be setting the value by default in the
//"PostPersist" method            

PostPersist方法:

/**
* @ORM\PostPersist
*/
public function setDownloadLinkValue ()
{
    $this->downloadImage = $this->getImageName(); //Yes yes, i have tried both, with "getImageName()" and "imageName"
}

我认为这是一个非常愚蠢的错误,但不是100%肯定,如果您需要在我的代码中看到其他内容,请告诉我,以便我可以更新此帖子

0 个答案:

没有答案