I have already commented on this topic, but it seems that it is dead, so I open a new one: Thin platform 3rd dependency dependency
The above article explains how to pass the Slims container to a class you wrote yourself.
However, the OP asked whether it is possible to get their Slim to Dependency Inject ALL classes .
I am also interested to know if there is a way to do this, since it seems to be anything but DRY if you need to pass a container to every class that you want to use.
As an example, if I want to use one of the Slim functions (for example, do a redirection in one of my own classes ), I cannot use this according to the documentation:
$res->withStatus(302)->withHeader('Location', 'your-new-uri');
Because $res(the response object) does not fall into the scope of my class unless I insert / pass it.
The problem with this is, if I say 100 classes, do I need to pass (or enter) the container 100 times? It really is really tiring.
On systems like CakePHP, you can use the "AppController" to globally use such things, that is, define things once and make them available in ALL of your classes. Does Slim provide this functionality? If not, then a serious flaw, IMO.
- , , :
- http://slimframework.com/docs/tutorial/first-app.html - PDO .
, 100 ( .. /classes/ ) index.php spl_autoload_register(). .
- 100 , , , PDO- ( ), , .. .