Web Development

The widget is fun way for Yii to create logic into views. To pass parameters to a widget, you would add them as properties to the widget class.


class MainMenuWidget extends CWidget
    // A property
    public $title = '';

    public function run()
        $categories = Category::model()->findAll();
        $this->render('mainMenuWidget', array('menu_items'  => $categories));


You need only pass an array as the second parameter of $this->widget.

$this->widget('MainMenuWidget', array('title' => 'my page title');

Nice huh!