[TYPO3-mvc] FAL - create FileReference from within a frontend controller action

Helmut Hummel helmut.hummel at typo3.org
Fri Oct 31 16:36:00 CET 2014


Hi Jan!

On 31.10.14 16:05, Jan Kornblum wrote:
>> But i still get the same error with "setOriginalResource". Something else
>> must be wrong with my code:
>>
>> // Move the file from /tmp/anything
>> $movedFile = $storage->addFile($filePath, $targetFolder, $fileName);
>>
>> // Create new file reference
>> $newFile = $storage->getFile($movedFile->getIdentifier());
>> $newFileReference =
>> $this->objectManager->get('Xxx\\Yyy\\Domain\\Model\\FileReference');
>> $newFileReference->setOriginalResource($newFile);
>
> Hmm, what i don't understand: I want to create a FilereReference
> object, but after the empty object has been created i should use an
> additional method (setOriginalResource) which itself expects such an
> (not yet existing) object as given parameter. How should this work?

The one is the Extbase FileReference model and the other one (you need 
to set) is the FAL FileReference.

But for your use case it would be easier to add another method to your 
Extbase FileReference Model like that:

https://gist.github.com/helhum/9a274ac1c29b50eedd71

Then do this in your controller:

$movedFile = $storage->addFile($filePath, $targetFolder, $fileName);
$newFileReference =
$this->objectManager->get('Xxx\\Yyy\\Domain\\Model\\FileReference');
$newFileReference->setFile($movedFile);


> Sometimes Extbase is really hard, i've already spent so many hours with
> this problem :(

It's very easy to mix things up in this area, so did I.

Kind regards,
Helmut

-- 
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 CMS Active Contributor, TYPO3 Security Team Member

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the TYPO3-project-typo3v4mvc mailing list