Closed muayyad-alsadi closed 8 years ago
below is the implementation of two public methods dynamicPartial (or you might rename it to renderDynamicPartial) dynamicWidget (or you might rename it to renderDynamicWidget)
they should live in CBaseController
/***
* internally used method
***/
public function dynamicWidgetCallback() {
$params=func_get_args();
$class=array_shift($params);
$data=array_shift($params);
return $this->widget($class,$data, true);
}
/***
* renders a widget dynamically even when done between beginCache/endCache
***/
public function dynamicWidget($class, $data=NULL) {
$this->renderDynamic('dynamicWidgetCallback', $class, $data);
}
/***
* internally used method
***/
public function dynamicPartialCallback() {
$params=func_get_args();
$view=array_shift($params);
$data=array_shift($params);
$processOutput=array_shift($params);
return $this->renderPartial($view, $data, true, $processOutput);
}
/***
* renders a partial dynamically even when done between beginCache/endCache
* Note: be aware of $data passed by controller
***/
public function dynamicPartial($view, $data=NULL, $processOutput=false) {
return $this->renderDynamic('dynamicPartialCallback', $view, $data, $processOutput);
}
I'm not sure if the two internal callbacks should be protected or not
This solution seems a lot more intuitive than renderDynamic with a callback.
thank you daxpresents.
qiangxue I've not heard from you, what do think about this ?
renderDynamic is defined in CController, not CBaseController. I hope we can have something like $this->beginDynamic() and $this->endDynamic(), rather than wrapper of existing methods.
I know but I want to be able to call it inside widgets that's why I suggested to define it in CBaseController.
I hope we can have something like $this->beginDynamic() and $this->endDynamic(), rather than wrapper of existing methods.
that's a very good suggestion although I believe having a dynamic partial or widget will cover most of my needs in an intuitive way and using a small thin wrapper over a tested method
usually we have a block made as a partial like _recent_items that is reused all over the site it would still be a partial even if we do not use cache at all
caching is very important, and it's very important to decrease the number of factors that let the cache varies or skipped
we used to skip full html caching (using beginCache) when a flash message is set we used to skip the cache if user is logged in (eg. to show "welcome Ahmad" box ..etc)
the solution to this is renderDynamic but its interface is not very useful
we I suggest having the following two interfaces that mimics renderPartial and renderWidget
for example we replaced
with
and we can use