gpt4 book ai didi

yii - 仅在模块中加载 Yii Bootstrap

转载 作者:行者123 更新时间:2023-12-04 10:01:47 27 4
gpt4 key购买 nike

我尝试仅在管理模块中加载 Yii Bootstrap 扩展,但它不起作用。我假设我需要预加载它或以某种方式启动它......谢谢!

    class AdminModule extends CWebModule
{
public function init()
{
// import the module-level models and components
$this->setImport(array(
'admin.models.*',
'admin.components.*',
'ext.bootstrap.components.Bootstrap',
));
}

public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
$this->layout = 'admin';
return true;
}
else
return false;
}
}

最佳答案

有 4 种不同的方法可以做到这一点:

  • 将配置添加到应用程序的配置(protected/config/main.php):
    'modules'=>array(
    'admin'=>array(
    'preload'=>array('bootstrap'),
    'components'=>array(
    'bootstrap'=>array(
    'class'=>'ext.bootstrap.components.Bootstrap'
    )
    ),
    // ... other modules ...
    )
  • 预加载到 init :
    public function init()
    {
    // import the module-level models and components
    $this->setImport(array(
    'admin.models.*',
    'admin.components.*',
    // 'ext.bootstrap.components.Bootstrap', // this will go to app config for components
    ));
    Yii::app()->getComponent('bootstrap');// this does the loading
    }
  • 预加载 init其他方式:
    public function init()
    {
    // import the module-level models and components
    $this->setImport(array(
    'admin.models.*',
    'admin.components.*',
    ));

    $this->configure(array(
    'components'=>array(
    'bootstrap'=>array(
    'class'=>'ext.bootstrap.components.Bootstrap'
    )
    )
    ));
    $this->getComponent('bootstrap');
    }
  • 预加载 init还有一种方式:
    public function init()
    {
    // import the module-level models and components
    $this->setImport(array(
    'admin.models.*',
    'admin.components.*',
    ));

    $this->configure(array(
    'preload'=>array('bootstrap'),
    'components'=>array(
    'bootstrap'=>array(
    'class'=>'ext.bootstrap.components.Bootstrap'
    )
    )
    ));
    $this->preloadComponents();
    }
  • 关于yii - 仅在模块中加载 Yii Bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13844509/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com