![]() |
Auto load Library before all Controllers - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Auto load Library before all Controllers (/showthread.php?tid=13743) |
Auto load Library before all Controllers - El Forum - 12-03-2008 [eluser]Ty Bex[/eluser] I would like to make a library available to all contollers. My Library is in the application/libraries/Auth_user.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Currently my controller is /application/controllers/backend/welcome.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); What I want to do is just call the library and not have to load the library for every page. (Commented out line) Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I am not 100% where to go with this one...Thanks in advance Auto load Library before all Controllers - El Forum - 12-03-2008 [eluser]Michael Wales[/eluser] application/config/autoload.php Auto load Library before all Controllers - El Forum - 12-04-2008 [eluser]xwero[/eluser] Instead of loading the libraries and helper in your custom library you better add them to the autoload file too. This way if you change from authentication library your other code doesn't break. Auto load Library before all Controllers - El Forum - 12-04-2008 [eluser]Ty Bex[/eluser] Thanks so much for your help. I should never be coding after a 16 hour work day. I was editing a backup of my autoload.php xwero Quote:Instead of loading the libraries and helper in your custom library you better add them to the autoload file too. This way if you change from authentication library your other code doesn’t break. They are in my autoload.php but I have to $CI =& get_instance(); im my library.. Don't I?? Code: $autoload['libraries'] = array('database', 'email', 'validation', 'session', 'encrypt', 'l_auth_user' ); application/libraries/L_auth_user.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Auto load Library before all Controllers - El Forum - 12-04-2008 [eluser]Rick Jolly[/eluser] I think xwero means that you shouldn't load files only within your custom library if they are used in other parts of your application. You haven't done that, so you're ok. I agree that you should load all files necessary within custom libraries regardless if they are loaded elsewhere. It doesn't hurt, since the CI loader will never load a file more than once. It prevents problems when someone removes a file from the autoload array. For the record, I don't use autoload for that reason and because it isn't transparent: you can't look through the code to see which files are being loaded. |