I'm using Yii with YiiBooster extension. I want to have a popover like this:
array(
'header' => '',
'value' => function($data)
{
$this->widget('bootstrap.widgets.TbButton', array(
'label'=>'Inne',
'type'=>'primary',
'size' => 'mini',
'htmlOptions'=>array(
'data-placement'=>'right',
'data-content'=> "Controller::renderPartial('_statButtons',
array('data' => $data->idProject));",
'rel'=>'popover'
),
));
}
),
This is inside the cell of the gridview. I would like to use renderPartial
to render a file with some content but above code is not working. How can I achieve it?
EDIT: if the code exucutes (my code or the @Ruslans code) it is the result:
Here is the text from the _statButtons partial file. End of this file.
<a id="yw2" class="btn btn-primary btn-mini" rel="popover"
data-placement="right" data-original-title="" title="">Inne</a>
bellow code works. I use PHP 5.3
'value' => function($data) use($controller)
{
$controller->widget('bootstrap.widgets.TbButton', array(
'label'=>'Inne',
'type'=>'primary',
'size' => 'mini',
'htmlOptions'=>array(
'data-placement'=>'right',
'data-content'=> $controller->renderPartial('_test',
array('data' => $data->title), true),
'rel'=>'popover'
),
));
}
where $controller
is just reassignment of $this
var before CGridView
widget is rendered.
$controller=$this;
because in PHP 5.3 closures don't have access to $this
var
As far as I remember, PHP 5.4 can access $this
.
Calling Controller::renderPartial(....
- bad approach, because renderPartial
is not a static function, but called statically. And it should raise error, unless you turned them off.