CodeIgniter Forums

Full Version: CI4: How to autoload libraries like Database, Session etc
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please help me by providing a code snip for autoloading libraries like Database, Session etc.
In CI3 we use it as
PHP Code:
$autoload['libraries'] = array('user_agent''database''session'); 

What would be the equivalent of this line in CI4?

Thanks in advance.

I know that the CI 4 documentation is still a work in progress but here you go...
it depend on the libraries
session is a service now and can be accessed by

to get a database connection
Autoloading it like you're thinking of from CI3 isn't really a thing anymore, but it's simple to handle yourself. If you find that you need the same libs loaded every time, you can make a BaseController that all of your other controllers extend from. And you can load it from there.

Many times, though, you can simple get the class through Services, as puschie pointed out, whenever you need it. Session doesn't need to be loaded before you need it, though, as the first time it is used it will automatically be initialized.
(11-13-2018, 03:42 PM)php_rocs Wrote: [ -> ]@webdevron,

I know that the CI 4 documentation is still a work in progress but here you go...

Not at all the same thing. Easy to confuse due to the terminology, but the page you reference is about locating and using files when they are requested. It is not a "list of requested classes to automatically load at a certain time" which is what the OP is looking for.
Have you looked at the user guide yet? It's fairly up to date, I believe.

Use '(Confusedegment)' in place of '(:any)' reference the user guide. The changes in routing are fairly drastic but very powerful.

If you have a specific question we can help.