If a model needs an image, it seems to be a good idea to do this via filereference. First, there is the definition of what we may call $image in our model:
/**
* image
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $image = NULL;
/**
* Returns the image
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
*/
public function getImage() {
return $this->image;
}
/**
* Sets the image
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
* @return void
*/
public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image) {
$this->image = $image;
}
In the database, the column “image” is an integer, length 11, unsigned. To make the image display in the view, all we have to do is the following:
<f:if condition="{item.image}"><f:image src="{item.image.uid}" treatidasreference="1"></f:image></f:if>