2

我正在将引导程序加载到模块中:

'modules'=>array(
    'admin'=>array(
        'preload'=>array('bootstrap'),
        'components'=>array(
            'bootstrap'=>array(
                'class'=>'ext.bootstrap.components.Bootstrap',
                'responsiveCss' => true,
            ),
        )
    ),
),

在 GridView 我试图创建一个 TbButtonColumn:

array(
    'class'=>'bootstrap.widgets.TbButtonColumn',
    'htmlOptions'=>array('style'=>'width: 50px'),
),

这将返回一个 CException

未定义属性“CWebApplication.bootstrap”。

因为它指向主配置应用程序中显然不存在的引导程序,所以在模块中加载引导程序时如何引用它?

我试过了:

components.bootstrap.widgets.TbButtonColumn

admin.components.bootstrap.widgets.TbButtonColumn

admin.bootstrap.widgets.TbButtonColumn

4

1 回答 1

1

罪魁祸首在TbGridView 中init()

$popover = Yii::app()->bootstrap->popoverSelector;
$tooltip = Yii::app()->bootstrap->tooltipSelector;

将它们更改为此将有助于:

if (!($module=Yii::app()->controller->module)){// access as application component (original behavior)
    $popover = Yii::app()->bootstrap->popoverSelector;
    $tooltip = Yii::app()->bootstrap->tooltipSelector;
}
else {// access as module component 
    $popover = $module->bootstrap->popoverSelector;
    $tooltip = $module->bootstrap->tooltipSelector;
}

同样的两行TbListView也在,所以如果你使用TbListView,你可以做同样的改变。


更新:这似乎已经存在问题,那里发布的解决方案看起来更好:

$module = ( Yii::app()->controller->module ? Yii::app()->controller->module : Yii::app() );

$popover = $module->bootstrap->popoverSelector;
$tooltip = $module->bootstrap->tooltipSelector;
于 2012-12-15T03:35:55.230 回答