How to use renderDynamic from within a Widget

(Edanbarak) #1

Say I have a widget PostWidget that displays a certain post and in that widgets view I have a piece of content that should be rendered dynamically (should not be cached)

So in my view I have:

	if($this->beginCache('showPost', $cacheConfig)) 


		$this->widget('PostWidget', array( 'id' => 1));



And in PostWidget’s view I have:


$this->controller->renderDynamic(array($this, 'getDynamicContent'));


Unfortunately it doesnt work - it only displays:


instead of the dynamic content.

Am I doing it wrong? Should I not use dynamic content from within a widget?

Any help would be appreciated!

(Maurizio Domba Cerin) #2

What does getDynamicContent do?

(Edanbarak) #3

It’s just a function that returns any dynamic content, like for example I am using it to return the HTML for a delete button if the user is allowed to delete this post.

The result of this function should not be cached since different users will have different permissions for posts - only some will be allowed to delete a certain post.

(Maurizio Domba Cerin) #4

Can you post here this function?

Note that the callback to renderDynamic should return the dynamic content instead of echoing it.

(Edanbarak) #5

Hello mdomba

It really doesnt matter what this function returns, it is just any HTML that should not be cached.

For argument sake lets say the function is:

public function getDynamicContent()


return 'some <b>html</b>';


I still get


returned instead of the dynamic content.

(Maurizio Domba Cerin) #6


I though that could be something in the method that is the reason for this… but just remembered that there where an issue with this in Yii 1.1.4 -…/detail?id=1565

try with the current trunk…