[TYPO3-mvc] Blog example: Number of comments
Julian Kleinhans
jk at marketing-factory.de
Thu Jul 30 10:50:22 CEST 2009
Hi Bastian,
Bastian Waidelich schrieb:
> Sebastian Kurfürst wrote:
>
> Hi there,
>
>> Thus, in your case, I'd rewrite the ViewHelper to have
>> <NAMESPACE:count array="{post.comments}" />.
>
> or, even more generic, <NAMESPACE:count collection="{post.comments}" />
> and in your render method:
>
> /**
> * @param array $collection
> */
> public function render($collection) {
> return count($collection);
> }
>
> note, that there is no array type hint. So Fluid would check that the
> collection is an array _or_ an object that implements the ArrayAccess or
> Traversable interface.
>
> I'd like to discuss this with you:
> Instead of marking the parameter as array, I'd like to turn it around
> and specify the interface.
>
> /**
> * @param Countable $collection
> */
> public function render($collection) {
> return count($collection);
> }
>
> Now Fluid could check, whether the parameter is an array or an object
> that implements countable (the same for Traversable and ArrayAccess)
>
> For the ForViewHelper we could expect a traversable object.
>
> What do you think?
>
> Bastian
I think its a good, really good idea.
Anyway, post.comments is a object and not an array
Is that viewHelper not one for the FLUID viewHelper extension?
cheers
julian
More information about the TYPO3-project-typo3v4mvc
mailing list