Php Symfony保存不同型号的对象
我有一个模型Php Symfony保存不同型号的对象,php,symfony1,doctrine,symfony-1.4,symfony-forms,Php,Symfony1,Doctrine,Symfony 1.4,Symfony Forms,我有一个模型海报,服务器存储图像。因此,模型有一个文件名字段。我有一个表单类MakenewForm.php,我需要重写它的doSave(),以便为Poster对象实现保存。MakenewForm有一个文本字段,该字段使用imagettftext写入预设图像。所以为了省钱,我需要 1. save the modified image data onto a file in the filesystem. 2. save an object of Poster class with filenam
海报
,服务器存储图像。因此,模型有一个文件名
字段。我有一个表单类MakenewForm.php
,我需要重写它的doSave()
,以便为Poster
对象实现保存。MakenewForm
有一个文本字段,该字段使用imagettftext
写入预设图像。所以为了省钱,我需要
1. save the modified image data onto a file in the filesystem.
2. save an object of Poster class with filename field set to the newly saved file
对于步骤1,我想为新文件获取一个随机名称。我知道symfony对上传的文件使用随机文件命名(文件输入小部件和文件验证程序
),我想使用相同的功能,但我找不到它是哪一个
对于步骤2,由于这个
$con
变量,我有点困惑。它有什么用?我如何使用它来满足我的需求?嗯,我总是可以通过将对象设置为PosterForm
并设置适当的字段并调用doSave
来实现保存。但是我想覆盖表单的默认doSave()
函数。我的MakenewForm
扩展了PosterForm
:P步骤1:函数是
generateFilename
,它位于sfValidatedFile.class.php
文件中(,也请看这个)
第2步:查看,on file upload部分,特别是清单2-20,其中显示了如何使用选择的文件名保存表单中的文件