Calling RenderPartial in a loop

Hi there,

I am still in development state of making a yii-based forum.

You see… in every forum there is a topic containing a list of posts.

In my understanding to display the posts, we just need to call renderPartial function in a loop to display the posts one by one in the Controller.

I’ve stumbled upon this website just now:

A person says that "calling a render partial inside a loop would request the rendering engine for each run.", hence I assume that it will slow the process.

If calling render partial inside a loop is not a good practice, then how do we handle this in Yii Framework?

it’s not Yii renderPartial being discussed there. I believe all Yii’s renderPartial does is provide you a reusable ui component.

As for your case, you would not need to do a renderpartial in loop. Check yii blog example to see how it can be done -

Yii Blog Example- How to display posts

I’ve looking for a solution to rendering items with renderPartial.

The proposed solution has for input a Yii object, i wonder how to do something like this:

view.php




<?php $this->renderPartial('_view', array(

    'data'=>array(

              array('id'=> 222,'name'=> 'Norton'),

              array('id'=> 333,'name'=> 'Pepe'),

          )

)); ?>

_view.php


<?=$data->name."(".$data->id.")" ?>



And the result output be:

Norton ( 222 )

Pepe ( 333 )

Thank you in advance.

Why not use CListView?