Yii中单独为module加载Bootstrap或…

来源:互联网 发布:最新赚钱软件 编辑:程序博客网 时间:2024/05/16 05:20

Bootstrap中包含了丰富的Web组件,根据这些组件,可以快速的搭建一个漂亮、功能完备的网站。
但是有时候我们网站前台并不需要Bootstrap,只要管理后台使用Bootstrap,那么该如何单独为一个module加载Bootstrap呢?

这里有4中方法来实现这个:
1.在应用的配置文件中添加如下内容 (protected/config/main.php):

1
2
3
4
5
6
7
8
9
10
    'modules'=>array(
        'admin'=>array(
            'preload'=>array('bootstrap'),
            'components'=>array(
                'bootstrap'=>array(
                    'class'=>'ext.bootstrap.components.Bootstrap'
            )
        ),
    //...其他模块...
    )    

2.在模块初始化时加载:

1
2
3
4
5
6
7
8
9
10
    publicfunction init()
    {
        //import the module-level models and components
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
            //'ext.bootstrap.components.Bootstrap', // this will go to app configfor components
        ));
        Yii::app()->getComponent('bootstrap');//this does the loading
    }

3.模块初始化加载的另一种方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    publicfunction 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');
    }

4.模块加载时的另一种方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    publicfunction 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();
    }
0 0