In this episode, we dig into how to handle configuration in a Slim 3 project. Out of the box, Slim 3 doesn't give you a built-in way to handle config files, so we look at how to set this up ourselves so our code stays tidy and easy to manage.
We start by setting up some simple config files – one for the database and another for app-level settings. The idea here is to easily swap out or tweak your configuration without digging through code all over your project. To help with this, we bring in the hassankhan/config
package (via Composer) to manage loading different config formats (like PHP, JSON, etc.) in a clean way.
You'll see exactly how to wire up configuration so it's accessible from your dependency container, and how to use those config options when setting up things like PDO for database access. We also set up a separate section for app settings, and show how you can pull those values into your routes as needed.
In short, by the end of this episode, you'll understand how to structure, load, and access configuration files in a Slim 3 project—making your code way more flexible and manageable in the long run.