Yii Framework Forum: Is There A Way To Dynamically Render A Widget? - Yii Framework Forum

Jump to content

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

Is There A Way To Dynamically Render A Widget? Rate Topic: -----

#1 User is offline   Dirk Willbrandt 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 27-May 14

Posted 27 May 2014 - 04:40 AM

Hello,

i'm developing for some time with Yii now, and now i got a new challange in developing with Yii :)

I want to cache whole pages with the COutputCache filter. This works fine, with any cache component. Now i need to use a widget in my main layout and some single views, but this widget has to return different values for different devices (e.g. for desktop, tablet or smartphone) AND different top level domains (e.g. .com, .de, .nl, in total 11 top level domains).

Currently i set an varyByExpression for the COutputFilter, which in my opinion is a bad workaround because there can be (actually) 44 different caches for one site.

I tried to use renderDynamic in the widget from the calling controller but it doesn't work.

Here is one example which i tried. The result in this case is that the random number is cached too:

layouts/main.php:
...some code...
<?php $this->widget('randomNumber'); ?>
...some code...


components/ownController.php:
...some code...
public function renderDynamicContentFullFilePath($viewFile, $data = null) {
 return $this->renderFile($viewFile, $data, true);
}
...some code...


components/randomNumberWidget.php:
...some code...
public function run() {
 $randomNumber = mt_rand();
 return $this->controller->renderDynamic('renderDynamicContentFullFilePath', $this->getViewFile('randomNumber'), array('randomNumber' => $randomNumber));
...some code...


components/views/randomNumber.php:
<?php echo $randomNumber; ?>


I tried same example code with an subtemplate which is renderd in the layout with an renderDynamic surrounding it. This works, but i find this is blowing the whole code up.

Is there any other solution that works without a new subtemplate?

I hope anybody can help me :)

Dirk
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