ventoh
(Giovanni N)
January 30, 2012, 5:32pm
1
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?
mbi
(mbi)
January 30, 2012, 5:44pm
2
$this->widget('LikeButton');
aarthi
(Aarthipandey Msc)
September 4, 2012, 5:12am
4
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()
{
$this->render('tabwidget');
}
}
view code is:
$this->widget(‘zii.widgets.jui.CJuiTabs’, array(
'tabs'=>array(
'Farmer Profile' =>$this->renderPartial("farmers/_view", array('model' => $model), $this),
'Farm Profile' =>$this->renderPartial("farmerFarm/_form", array('model' => $model), $this),
// 'Address' =>$this->renderPartial("address/_form", array('model' => $model), $this),
),
'options'=>array(
'collapsible'=>true,
),
));
the problem is i am getting error as "Undefined variable: model " Can anyone help me to solve this
yugenekr
(Yugenekr)
September 5, 2012, 5:42am
5
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]