How to connect the startup database library |
In CI4, you don't autoload things in the same way as previous versions, since we now have a PSR4-compliant autoloader built in. As per the docs, whenever you need a database connection, you simply grab it:
Code: $db = \Config\Database::connect(); You can do that in your controller constructor, if you like to have it available for every method. Or in a BaseController that your controllers extend from. |
Messages In This Thread |
How to connect the startup database library - by evgeny - 02-02-2017, 12:44 PM
RE: How to connect the startup database library - by Wouter60 - 02-02-2017, 02:19 PM
RE: How to connect the startup database library - by kilishan - 02-02-2017, 09:42 PM
RE: How to connect the startup database library - by zarbux - 03-19-2017, 01:50 PM
RE: How to connect the startup database library - by Wouter60 - 02-02-2017, 11:30 PM
RE: How to connect the startup database library - by kilishan - 02-03-2017, 11:55 AM
RE: How to connect the startup database library - by evgeny - 02-24-2017, 02:04 AM
|