Yii Framework Forum: using cache in widget renderContent method - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

using cache in widget renderContent method Rate Topic: -----

#1 User is offline   augustin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 07-April 10

Posted 23 December 2010 - 10:20 AM

when calling:

if (CBaseController::beginCache('newcattree')) {
...
CBaseController::endCache()
}

in widget's renderContent method, I got:

Fatal error: Call to a member function getUniqueId() on a non-object in C:\Users\Project Manager\workspace\f\yiiext\framework\web\widgets\COutputCache.php on line 265

What's wrong?

Regards
Augustin
0

#2 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 23 December 2010 - 10:29 AM

report it as a bug please
To solve your problem do something like this:
        	ob_start();
        	ob_implicit_flush(false);
        	//your code here
        	echo $content=ob_get_clean();
        	Yii::app()->cache->set('newcattree',$content);

--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#3 User is offline   augustin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 07-April 10

Posted 23 December 2010 - 10:39 AM

I think this solution with flushing the buffer ISN'T the good one. If I start flushing the buffer, I can't modify header (e.g. cookies, redirection, etc)

View PostGustavo, on 23 December 2010 - 10:29 AM, said:

report it as a bug please
To solve your problem do something like this:
        	ob_start();
        	ob_implicit_flush(false);
        	//your code here
        	echo $content=ob_get_clean();
        	Yii::app()->cache->set('newcattree',$content);


0

#4 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 23 December 2010 - 10:45 AM

yes you can
the buff will only be enabled for a little piece of code and wont interfer in actions like the ones you pointed out

I just checked COutputCache widget and it does exactly the same as i mentioned

This post has been edited by Gustavo: 23 December 2010 - 10:51 AM

--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#5 User is offline   augustin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 07-April 10

Posted 23 December 2010 - 12:30 PM

My fault.

Please refer to the guide on how to use fragment caching. Basically, you should use $this->controller->beginCache() instead of CBaseController::beginCache(). The latter calls the method in a static way, which is incorrect.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users