3

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>
Joe
  • 2,551
  • 6
  • 38
  • 60
  • what error does above code raise? – Ruslan Polutsygan May 08 '13 at 12:40
  • There is no error at all. The way above: it just puts the code as it is as text. If I remove the `"` - it is rendered not inside the `data-content` but as a text that is placed before the button. – Joe May 08 '13 at 12:46

1 Answers1

3

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.

Ruslan Polutsygan
  • 4,401
  • 2
  • 26
  • 37
  • The code executes it's true but my code executes too. The problem is that it doesn't put it into the `data-content` option but it is rendered before the button. I added resulting HTML of your code in my question. – Joe May 08 '13 at 13:08
  • 1
    @Joe: in your case two params are passed into `renderPartial`, in my case there is third param equals to `true`, which says that view content has to be returned, not outputed directly http://www.yiiframework.com/doc/api/1.1/CController#renderPartial-detail – Ruslan Polutsygan May 08 '13 at 13:24
  • Oh, my bad - I haven't noticed that. Thank you very much! – Joe May 08 '13 at 13:32
  • Just a little question at the end - what should I do to put a link into the popover? I tried to use `'data-html' => true` inside the `htmlOptions` but it doesn't work. – Joe May 08 '13 at 13:54
  • @Joe: the only solution I know is to run `popover` manually, http://www.yiiframework.com/extension/bootstrap/#c11590 – Ruslan Polutsygan May 08 '13 at 15:41