You are viewing revision #2 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
A big problem I've hit with the Yii-Bootstrap extension is that all AJAX requests are initializing Bootstrap because of preload. This is a huge waste of resources, especially when using AJAX-based file uploaders that split the file into chunks. Large file uploads using that method could be initializing bootstrap hundreds of times.
I ended up disabling preload and switched the loading of bootstrap to a filter.
Disable bootstrap preload: /protect/config/main.php
'preload'=>array(
//'bootstrap',
'log'
),
Create file: /protected/extensions/bootstrap/filters/BootstrapFilter.php
<?php
class BootstrapFilter extends CFilter
{
protected function preFilter()
{
Yii::app()->getComponent("bootstrap");
return true;
}
}
Then in a controller, add the new bootstrap filter:
public function filters()
{
return array(
'accessControl',
'postOnly + delete',
array('ext.bootstrap.filters.BootstrapFilter - delete')
);
}
This will load bootstrap for all actions in the controller, other than the "delete" action. If you wanted to disable loading bootstrap for another specific action, do the following:
array('ext.bootstrap.filters.BootstrapFilter - delete, uploadajax')
Make sure you add this filter to all site controllers that require bootstrap (this includes the Site controller to display errors)
This functionality could easily be added to the bootstrap Gii CRUD generation, and is a far better way to initialize this extension in my opinion.
Thank you
For this wiki and the PR on github... will also modify the asset registration as it is another challenge people facing when using the library the first time.
Bootstrap scripts
I did like below.
public function registerBootstrapScripts() { $bootstrap = Yii::app()->getComponent('bootstrap'); $bootstrap->responsiveCss = true; $bootstrap->jqueryCss = true; $bootstrap->coreCss = true; $bootstrap->yiiCss = true; $bootstrap->enableJS = true; $bootstrap->init(); }
This has the advantage, that I can use different css-frameworks in the frontend and backend.
Best method for using with modules?
Thanks for posting...this helped me figure out why my autocomplete fields were loading VERY slowly.
It seems as if the provided solution works best when all controllers reside in the yii app itself, and Joblo's solution is better when using extensions/modules that define their own controllers/views (where you don't want to change the module code directly).
Is there any solution that would work well for both use cases? It seems like bootstrap shouldn't be loaded for any request that does not render a view (or within a layout)?
Very nice
I had this problem and was looking for work around. This seem to solve my problem. Thanks
YiiBooster
It seems that YiiBooster has implemented this into their code, however it is currently an undocumented feature. For YiiBooster you just have to disable preloading then call the filter in a controller, no extra steps required.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.