I'm working on a page with widgets system and I'm facing two different kinds of problems.
How it should work:
My Page model (wich has widgets through HAS_MANY relation) has a text field called "layout". A typical layout content:
<div id="widget1" class="span6">Widget N°1</div><div id="widget2" class="span6">Widget N°2</div>
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:
$html=$this->widget('application.modules.content.widgets.'.$widget->type,array('widget'=>$widget));but it drops me an error:
Quote
Object of class SimpleWidget could not be converted to string
my simpleWidget.php :
<?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:
Quote
Undefined variable: widget
Any guidance will be much appreciated.

Help












