How to load the Yii-bootstrap extension in a specified action
I encountered a major problem when using Yii-Bootstrap extension, because the pre-loading mechanism made all AJAX requests initialize bootstrap. This is a great waste of resources, especially when AJAX-based file upload tools are used to split large file uploads, bootstrap will be initialized for hundreds of times.
In the end, I disabled the preload and used the filter to load the bootstrap.
Disable bootstrap preload:/protect/config/main. php
'preload'=>array( //'bootstrap', 'log' ),
Create a File:/protected/extensions/bootstrap/filters/BootstrapFilter. php
getComponent("bootstrap"); return true; } }
Then, add the bootstrap filter to the controller.
public function filters() { return array( 'accessControl', 'postOnly + delete', array('ext.bootstrap.filters.BootstrapFilter - delete') ); }
In this way, bootstrap will be loaded in other actions except the delete action. if you need to disable bootstrap loading for other specified actions, use the following code:
array('ext.bootstrap.filters.BootstrapFilter - delete, uploadajax')
Make sure you add this filter to all controllers of the site (including controllers that display error messages)
This method can be easily added to the Gii CRUD generator. in my opinion, this is a better method to initialize this extension.
This article translated from foreign language website, view the original, please click: http://www.yiiframework.com/wiki/434/load-the-yii-bootstrap-extension-on-specific-actions/