Home  >  Article  >  Backend Development  >  4 ways to load Bootstrap or other components separately for modules in Yii_PHP Tutorial

4 ways to load Bootstrap or other components separately for modules in Yii_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 16:57:20876browse

Bootstrap contains a wealth of web components. Based on these components, you can quickly build a beautiful and fully functional website. But sometimes we don’t need Bootstrap in the frontend of our website. We only need to use Bootstrap in the management backend. So how do we load Bootstrap for a module separately?

Here are 4 ways to achieve this:
1. Add the following content to the application configuration file (protected/config/main.php):

PHP

The code is as follows Copy code
'modules'=>array(
 代码如下 复制代码
    'modules'=>array(
        'admin'=>array(
            'preload'=>array('bootstrap'),
            'components'=>array(
                'bootstrap'=>array(
                    'class'=>'ext.bootstrap.components.Bootstrap'
            )
        ),
    // ...其他模块...
    )   
         'admin'=>array(

'preload'=>array('bootstrap'),

            'components'=>array(

'bootstrap'=>array(

‘class’=>’ext.bootstrap.components.Bootstrap’
 代码如下 复制代码
    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
    }
) ), // ...Other modules... ) )
2. Load during module initialization:
The code is as follows Copy code
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 }


3. Another method for module initialization loading:

{                // import the module-level models and components
The code is as follows
 代码如下 复制代码

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

Copy code


PHP
 代码如下 复制代码

PHP
    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();
    }

Public function init()
           $this->setImport(array(               'admin.models.*',

              'admin.components.*',

)); $this->configure(array(               'components'=>array(                     'bootstrap'=>array( 'class'=>'ext.bootstrap.components.Bootstrap' ) ) ));            $this->getComponent('bootstrap'); }
4. Another method when loading modules:
The code is as follows Copy code
PHP 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(); } http://www.bkjia.com/PHPjc/631525.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631525.htmlTechArticleBootstrap contains a wealth of Web components. Based on these components, you can quickly build a beautiful and fully functional website. . But sometimes we don’t need Bootstrap at the front end of our website, we just...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn