How to load the Yii-bootstrap extension in a specified action

Source: Internet
Author: User
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/

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.