[TYPO3-mvc] Use index of iteration attribute as array index

Dmitri Pisarev dimaip at gmail.com
Wed Jul 6 13:54:30 CEST 2011


I have added another function to my Article model class as this:
	/**
	 * Constructs the wrapper object for images and their captions
	 *
	 * @return array() $imagesWithCaptions
	 */
	public function getImagesWithCaptions() {
		$captions = $this->getCaptions();
		foreach ($this->getImages() as $key => $image) {
			$array[$key]['image'] = $image;
			$array[$key]['caption'] = $captions[$key];
		}
		return $array;
	}
now I can use article.imagesWithCaptions and it works just fine.

I always had A QUESTION: is using such faux getters is a valid design 
pattern?

Regards,
Dmitri.

06.07.2011 15:35, Dmitri Pisarev пишет:
> Whoa, Claus, it's kind of funny we ran into the same problem almost
> simulaneously. I need to show a caption for the image inside the foreach
> images loop. I'll also use a wrapper object then.
>
> Sebastian, do you mean Tx_Extbase_Reflection_ObjectAccess? I didn't
> quite get how to use it to write such a ViewHelper.
>
> Regards,
> Dmitri.
> 27.06.2011 11:55, Sebastian Kurfürst пишет:
>> Hey,You could give
>>
>>> {imgSrc.{index}} a try as this would be the logic expression to first
>>> substitute index. Your current expression IMO will always look for
>>> named property index of imgSrc.
>>> [...]
>> This won't work, as this kind of expression is not recognized by Fluid.
>>
>> If you need such (kinda esoteric) expressions, I'd go for a custom
>> ViewHelper which wraps Tx_Extbase_Utility_ObjectAccess.
>>
>> Greets,
>> Sebastian
>



More information about the TYPO3-project-typo3v4mvc mailing list