This allows me to have a preview of page’s layouts.
My Widget model (belongs_to page) has a text field called "body" and three string field called
"title"
"widgetId" (like widget1)
"type (like simpleWidget)
This is my view:
<?php echo $model->layout; ?>
<?php
foreach($model->widgets as $widget){
$html=$widget->title;
$widgetId=$widget->widgetId;
// below it drops me the first error
//$html=$this->widget('application.modules.content.widgets.'.$widget->type,array('widget'=>$widget));
// below, for testing purpose, drops me the second error
//$this->widget('application.modules.content.widgets.'.$widget->type,array('widget'=>$widget));
?>
<script>document.getElementById("<?php echo $widgetId; ?>").innerHTML="<?php echo $html;?>"</script>
<?php
}
?>
As you can see, I want to update my widget1, widget2 … divs with a simple javascript trick. Code above work, each widget title appears in the right div.
But I want to update the divs with the output of the widget like this:
<?php
class SimpleWidget extends CWidget
{
public $widget;
public function init()
{
parent::init();
}
public function run()
{
echo "<h3>test</h3>";
//echo "<h3>test ".$widget->title."</h3>";
//echo $widget->body;
}
}
?>
if I uncomment the two last echo, I’ve got the second error:
the TbListView doesn’t load all the javascript stuff (this is understandable because mt trick is to substitute the html content of all my widgets in page)
<?php
class SimpleWidget extends CWidget
{
public $widget;
public function init()
{
parent::init();
}
public function run()
{
echo "<h3>test</h3>";
echo "<h3>test ".$this->widget->title."</h3>";
echo $this->widget->body;
}
}
?>
I know that doing this buisiness logic in view is bad practice, but it’s the only way I’ve found to register all necessary scripts and css needed by TbListView and other bootstrap goodies …