Four Methods for loading Bootstrap or other components for module separately in Yii _ PHP Tutorial

Source: Internet
Author: User
In Yii, you can load Bootstrap or other components for the module separately. Bootstrap contains a wide range of Web Components. Based on these components, you can quickly build a beautiful and fully functional website. However, sometimes the front-end of our website does not need Bootstrap. only Bootstrap contains a wide range of Web Components. Based on these components, we can quickly build a beautiful and fully functional website. However, sometimes we do not need Bootstrap at the front end of our website. as long as Bootstrap is used in the management background, how can we load Bootstrap for a module separately?

Here are 4 methods to implement this:
1. add the following content (protected/config/main. php) to the application configuration file ):

PHP

The code is as follows:
'Modules' => array (
'Admin' => array (
'Preload' => array ('bootstrap '),
'Components' => array (
'Bootstrap '=> array (
'Class' => 'ext. bootstrap. components. Bootstrap'
)
),
//... Other modules...
)

2. load during module initialization:

The code is as follows:
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 initialization and loading of modules:

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


4. another method for loading modules:

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 (
'Preload' => array ('bootstrap '),
'Components' => array (
'Bootstrap '=> array (
'Class' => 'ext. bootstrap. components. Bootstrap'
)
)
));
$ This-> preloadComponents ();
}

Bytes. However, sometimes the front-end of our website does not need Bootstrap, just...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.