3

我正在使用带有 YiiBooster 扩展的 Yii。我想要一个像这样的弹出窗口:

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'
                ),
            ));
        }
    ),

这是gridview的单元格内。我想renderPartial用一些内容来渲染一个文件,但上面的代码不起作用。我怎样才能实现它?

编辑:如果代码执行(我的代码或@Ruslans 代码)它是结果:

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>
4

1 回答 1

3

波纹管代码有效。我使用 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只是在呈现小部件$this之前重新分配 var 。CGridView

$controller=$this;

因为在 PHP 5.3 中,闭包无法访问$thisvar

据我记得,PHP 5.4 可以访问$this.

调用Controller::renderPartial(....- 不好的方法,因为renderPartial不是静态函数,而是静态调用。它应该会引发错误,除非您将它们关闭。

于 2013-05-08T12:53:45.110 回答