Answer the question
In order to leave comments, you need to log in
How is dependency injection (Slim PHP) implemented in this code?
// Create app
$app = new \Slim\App();
// Get container
$container = $app->getContainer();
// Register component on container
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('path/to/templates', [
'cache' => 'path/to/cache'
]);
Answer the question
In order to leave comments, you need to log in
$app
the root of the application, request containers and put a view function there to create a wrapper over the displays. The framework will call the function itself
$container['view'](передаст сюда линк на app->контейнер)
we initiate the view and return the instance to work with the view. $this->view->render(...)
(magic methods) our wrapper with the method is calledrender
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question