[TYPO3-mvc] Blog example: Number of comments

Jochen Rau jochen.rau at typoplanet.de
Tue Jul 28 09:31:29 CEST 2009


Hi all.

Joerg Schoppet wrote:
> Steffen Ritter schrieb:
>> Just implement a getter for commentCount ;)
>> return count($this->comments)
> I see three possibilities:
> 1. mentioned by Steffen
> Implement a method in class Post, which ist called getCommentCount()
> with the body written above.
> Then you can do in the template {post.commentCount}
> But I think this is not the way OO and the implementation of fluid
> should be used.
> 2. in the action method, just assign an additional var like
> $this->view->assign('commentCount', count($post->getComments()));
> Then you can do in the template {commentCount}
> 3. What you mentioned with an own viewhelper.
>
> I would prefer solution 2. Solution 3 seems to be to "heavy".

Just a few comments:

This issue is related to http://forge.typo3.org/issues/show/3596

The Domain Model Post should only implement methods of the domain. The 
method getAmountOfComments() of solution #1 is IMO more output related 
than domain related. So, let's try it another way.

Solution #2 is a better way to do it but a little bit costly.

Solution #3 is the most convenient way and my preferred solution. But - 
it is also too costly.

Even more, we have to be aware of Lazy Loading. To give an example The 
Posts inside a Blog are only loaded on demand. No Post is loaded if 
there is only the list of Blogs rendered. BUT if you loop over the blogs 
and say count($posts) all Posts will be loaded. That hits the database 
more than expected (a so called "ripple loading").

We can solve this problem by implementing the Countable interface to the 
Lazy Loading Proxy and the Object Storage. The information can be 
retrieved at reconstitution time or via database call inside the Lazy 
Loading Proxy.

Regards
Jochen

-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list