call widget in controller

I create a widget in components/LikeButton.php


class LikeButton extends CWidget

{

  public function run()

  {

     $this->render('likeButton');

  }

}



and the view in components/views/likeButton.php


<div>Hello i'm the like button</div>

So, i want to call this widget from components/Controller.php


LikeButton::run() 

throw an exception "view not found". How can i accomplish this?




$this->widget('LikeButton');



tks, it worked!

I have done same things, like i have created widget in components (components/TabWidget.php), and created views in component/views/tabWidget.php and called as this->widget(‘TabWidget’)); code of TabWidget.php in component is

class TabWidget extends CWidget

{

public function run()

{

 &#036;this-&gt;render('tabwidget');

}

}

view code is:

$this->widget(‘zii.widgets.jui.CJuiTabs’, array(

    'tabs'=&gt;array(


            'Farmer Profile' =&gt;&#036;this-&gt;renderPartial(&quot;farmers/_view&quot;, array('model' =&gt; &#036;model), &#036;this),


            'Farm Profile' =&gt;&#036;this-&gt;renderPartial(&quot;farmerFarm/_form&quot;, array('model' =&gt; &#036;model), &#036;this),


           // 'Address' =&gt;&#036;this-&gt;renderPartial(&quot;address/_form&quot;, array('model' =&gt; &#036;model), &#036;this),





    ),


    'options'=&gt;array(


            'collapsible'=&gt;true,


    ),


    ));

the problem is i am getting error as "Undefined variable: model " Can anyone help me to solve this

You use $model, but didn’t actually pass it to view file, e.g.

[color="#1C2837"]


$this->render('tabwidget', array('model'=>$model));

[/color]

[color="#1C2837"]or declaring it as widget property and then calling as $this->model in widget view file.[/color]

[color="#1C2837"]Of course, $model object should be passed to widget or initiated there, depends on your code.[/color]