Answer the question
In order to leave comments, you need to log in
How to work with containers in Slim, what is the logic of building dependencies?
Confused ). Let's say there are 2 objects or modules (what is the correct name?). Twig template engine and Eloquent ORM.
1. I stuff them into containers accordingly
$container['view'] = function ($container) {
$view = new \Adbar\Slim\Views\Twig('path/to/templates');
...
};
$container['db'] = function ($container) {
$capsule = new \Illuminate\Database\Capsule\Manager;
...
}
$app->get('/', 'App\PageController:index');
Answer the question
In order to leave comments, you need to log in
Slim itself passes containers to the called controller.
That is, in the controller in the constructor you accept containers:
public function __construct($container) {
$this->container = $container;
}
$this->container->view;
$this->container->db;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question