Making $db available globally |
You are missing some OOP notions. In your example, $db is a local variable, not a class property. You need to assign it to $this->db.
But, I wouldn't advise you to do that. Database queries should be done in models, not in controllers. CI is very flexible and won't prevent you from doing database requests everywhere, but your application will be hard to maintain and debug if you have SQL all over the place instead of following the MVC pattern. |
Messages In This Thread |
Making $db available globally - by CodingInCodeigniter - 10-15-2021, 09:53 AM
RE: Making $db available globally - by includebeer - 10-16-2021, 06:56 AM
RE: Making $db available globally - by sr13579 - 10-16-2021, 04:50 PM
RE: Making $db available globally - by iRedds - 10-16-2021, 09:11 PM
RE: Making $db available globally - by donpwinston - 10-17-2021, 12:55 AM
RE: Making $db available globally - by includebeer - 10-17-2021, 04:28 AM
|