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...