CHtml or not ?

Hi guys!

I am making a dynamic menu where the values ​​come from the database. This menu will be displayed using the portlets.

My question is if I should use the CHtml for the various elements, eg. ul, li, a… through the methods CHtml::tag(), CHtml::openTag(), CHtml::link() etc… to build this menu?

Since I am using two foreach (parent and child) to display the values ​​that come from two related tables, using CHtml will lower the performance?

Take a look at this discussion: CHtml.

I would use CHtml if it saves time, in my opinion it’s not a bad performance issue.

But I would cache the whole menu/portlet html output, so that not on every request the menu is created from the db.

You can clear the cache (onsave) if the menu items are changed in the db.

This will lead to a good performance.

The caching is being done, my only doubt was if I should use the CHtml to the elements and I’ll probably use. As you said, the performance is not so bad and the caching will lead for a good performance.

Ty for replying Joblo.