Quantcast
Channel: Insane in the Main Frame
Viewing all articles
Browse latest Browse all 310

Extbase: handle images in model

$
0
0

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:

  1. /**
  2. * image
  3. *
  4. * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
  5. */
  6. protected $image = NULL;
  7. /**
  8. * Returns the image
  9. *
  10. * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
  11. */
  12. public function getImage() {
  13. return $this->image;
  14. }
  15. /**
  16. * Sets the image
  17. *
  18. * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
  19. * @return void
  20. */
  21. public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image) {
  22. $this->image = $image;
  23. }

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:

  1. <f:if condition="{item.image}"><f:image src="{item.image.uid}" treatidasreference="1"/></f:if>

Viewing all articles
Browse latest Browse all 310

Trending Articles