[TYPO3-dev] FAL: Remove files in frontend extension
Klaus Heuer
post at heuer-illustration.de
Tue Apr 22 16:53:17 CEST 2014
Hi Frans,
the debug output was exactly the same, if I add an Image via Backend TCA
Form or Frontend ...
I solved the image remove function now directly in the controller:
public function savePostAction() {
...
if ($post['imagedelete'] == 1) {
$images = $DBPost->getImage();
foreach ($images as $img) {
//remove the file reference
$reference =
$this->fileReferenceRepository->findByUid($img->getUid());
$this->fileReferenceRepository->remove($reference);
//remove the image in model (only one image allowed)
$DBPost->setImage(null);
}
}
...
I know, that is not an "ideal solution" but it works;) The images can
now added / deleted via Backend TCA Form and Frontend editing (without
deleting the image file itself).
Thanks for your help,
Klaus
Am 22.04.14 16:27, schrieb Frans Saris:
> Hi Klaus,
>
> could you do a var_dump() on $this->files to see what is in there?
>
> gr. Frans
>
>
> 2014-04-22 11:44 GMT+02:00 Klaus Heuer <post at heuer-illustration.de>:
>
>> Hi list,
>>
>> in my extbase extension I need a FRONTEND image upload / delete function
>> with FAL.
>>
>> The upload function is working well, thanks to Frans for his bitbucket
>> fal_fe_upload snippet.
>>
>> But how to detach a file?
>>
>> class my model
>> /**
>> * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\
>> TYPO3\CMS\Extbase\Domain\Model\FileReference> $file
>> *
>> */
>> protected $file;
>> ...
>> /**
>> * Adds a file // this is working well
>> *
>> * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $file
>> *
>> * @return void
>> */
>> public function addFile(\TYPO3\CMS\Extbase\Domain\Model\FileReference
>> $file) {
>> $this->files->attach($file);
>> }
>>
>> /**
>> * Removes a file // will not work
>> *
>> * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $file
>> * @return void
>> */
>> public function removeFile($file) {
>> $this->files->detach($file);
>> }
>>
>> Ends in Error: Call to undefined function detach() ....
>>
>> I will not remove the file itself, only the entry in the file reference
>> table...
>>
>> There are some hints in the net, that I have to build my own database
>> query here, but I can't belive, that an attach is working - and for a
>> detach I have to build the complete query by my own.
>>
>> Have someone done similar and can give me a hint?
>>
>> System: TYPO3 6.2.1
>>
>> Thanks, Klaus
>>
>>
>> _______________________________________________
>> TYPO3-dev mailing list
>> TYPO3-dev at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev
>>
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev
More information about the TYPO3-dev
mailing list