问题
I've the following libs in the autoload.php
:
$autoload['libraries'] = array('database', 'session');
I need the session lib everywhere - besides of ONE controller, where it causes only trouble. Now the question is:
Is there a possibility NOT to load the session lib for this special controller or is the only option to delete it from the autoload and add it to every single controller, where needed?
回答1:
In your autoload.php:
$autoload['libraries'] = array('database');
$CI =& get_instance();
if ($CI->router->fetch_class()!='conflictingcontroller') array_push($autoload['libraries'], 'session');
回答2:
Taken from this answer: Link
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.
However since it is a session
and not database
or uri
helpers, Kumar's answer may work for you.
回答3:
You can do as below in your controller constructor
$this->session = null;
or
unset($this->session);
来源:https://stackoverflow.com/questions/21577592/codeigniter-change-autoload-libraries-for-one-controller