• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI4: How to autoload libraries like Database, Session etc

#1
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.
My "Creative Parents" were created me on 11 December of 1990
Reply

#2
@webdevron,

I know that the CI 4 documentation is still a work in progress but here you go... http://codeigniter4.github.io/CodeIgnite...utoloading
Reply

#3
it depend on the libraries
session is a service now and can be accessed by
Code:
\Config\Services::session()

to get a database connection
Code:
\Config\Database::connect()
Reply

#4
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.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#5
(11-13-2018, 04:42 PM)php_rocs Wrote: @webdevron,

I know that the CI 4 documentation is still a work in progress but here you go... http://codeigniter4.github.io/CodeIgnite...utoloading

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.
Reply

#6
Thanks to all. I have some more problems. How can I express the following three lines in CI4?

PHP Code:
$route['(:any)/(:any)/(:any)' 'manage/$1/$2/$3';
$route['(:any)/(:any)'        'manage/$1/$2';
$route['(:any)'               'manage/$1'
My "Creative Parents" were created me on 11 December of 1990
Reply

#7
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.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.