[TYPO3-mvc] Blog example: Number of comments

Bastian Waidelich bastian at typo3.org
Thu Jul 30 10:37:51 CEST 2009


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


More information about the TYPO3-project-typo3v4mvc mailing list