I haven’t explored that tutorial much myself, but within a route’s closure, you would typically access your database using something like $this->db since $this is bound to $app at that point.
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Method has is not a valid method' in C:\xampp\htdocs\assessment_admin\composer\vendor\slim\slim\Slim\App.php:129 Stack trace: #0 C:\xampp\htdocs\assessment_admin\index.php(31): Slim\App->__call('has', Array) #1 C:\xampp\htdocs\assessment_admin\index.php(31): Slim\App->has('db') #2 {main} thrown in C:\xampp\htdocs\assessment_admin\composer\vendor\slim\slim\Slim\App.php on line 129
You sir are a clever one indeed! That was the solution. But the reason I was trying to run $app out in the open was because I wanted to pass it to my main class right away. This way the child classes could inherit all the db settings, etc. later on.
So I typically do something like this near the start of my applications:
$m = new Main();
$m->set_app($app);
That’s not going to work with SLIM 3 I guess but I’m sure there’s a slim way to do it.
How does one make the slim DIC available to inherited classes?
Well, you can pass the container itself to your classes, then you have access to anything within the DIC from your classes. But this isn’t considered good practice as it becomes service location rather than dependency injection. For info on this, check out this comment and the reply for info about not going the service location way.
Excellent resources @tflight … looks like I’ve got some studying to do. (after I digest all this info I’m sure I’ll have some more questions which I’ll post in another thread) Thanks again for all your timely and super helpful responses!