Reuse of Model display code

Hi there,

I’d like to know what the best practice for the following situation:

In my view I’ve got some logic to display the data of a model. I realised that I need the exact same code in a different view (with a different controller).

So I thought I should group together the display code of that model, and then both views would simply call it.

My question is where to put the code ? Does that make sense to have a method in the model displayModel() that returns the code (not very MVC) ? The view would simply contain <?php echo $model->displayModel() ?>. Or is it better to put this in a separate helper class ? Is there a better way to do this with the Yii framework?



check out this one

it could be done rendering partial from another controller’s view, however, it’s not a good practice.

as @zaccaria suggested, widget might be a way to go.

Thanks Rootbear, I forgot I could use widgets :slight_smile: