Not to load an autoload library in codeigniter

2019-03-04 12:41发布

问题:

I have a library which is used by all controllers. But for a specific controller i dont want to load that library. Is there any way i can stop loading that library for that controller.

i am using this command but its failing:
$this->load->library('xyz',array('autoload' => FALSE));

Thanks

回答1:

Autoloading is meant for site-global items.

A cleaner solution may be to extend the controller and load the library in that new controller's constructor. Then all of your controllers extend from that controller, except the one(s) you don't want to load that library - those can extend the original CI controller.

That should take you < 5 minutes to implement and you won't have to hack anything.



回答2:

You can take a look at this link:

http://xplus3.net/2010/05/31/conditional-auto-loading-of-libraries-in-codeigniter/

Basically, you'd be overwriting the autoload.php library to check for a variable. If that variable is false, then explicitly add the specific library to the autoload array.