A
A
Adrior2012-08-15 10:11:01
Yii
Adrior, 2012-08-15 10:11:01

How to get content between beginWidget and endWidget in widget code?

The Yii documentation has an example:

<?php $this->beginWidget('path.to.WidgetClass'); ?>
…некое содержимое, которое может быть использовано виджетом…
<?php $this->endWidget(); ?>

But nowhere can I find exactly how this content can be used.
I want to frame some html-code in the template as a widget, and build the output of the widget itself based on it. For example, by framing one element of a list as a widget, display a dynamic list based on data from the model.
Does anyone know how to get the contents between beginWidget and endWidget in the widget code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2012-08-15
@Adrior

www.yiiframework.com/doc/guide/1.1/en/basics.view#c4980

M
masterx, 2012-08-15
@masterx

Widget class:

<?php
class MyWidget extends CWidget
{
   public $prop1;
   public $prop2;

   public function run()
   {
      echo $this->prop1;
   }
}

?>

Widget call:
<?php $this->beginWidget('myWidget', array('prop1'=>'value1','prop2'=>'value2' ))?>

That is, the parameters passed to the widget must be predefined in the widget class itself, and must also be public.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question