Answer the question
In order to leave comments, you need to log in
How to push an array into DI in Yii2?
I can not understand how to solve the issue with DI. An array in dependencies is REQUIRED. But there is also a class that must be taken from the container. I'm trying to do it in different ways, but this question has not won yet. Maybe someone knows?
// PageCountry прописан в контейнере и берется от туда без проблем
class PageValue {
public function __construct(PageCountry $country, $values) {}
}
$value = \Yii::$container->get(PageValue::class, [], [$value]);
$value = \Yii::$container->get(PageValue::class, [$value]);
Answer the question
In order to leave comments, you need to log in
Everything is written there in the comments to the get method. Well, or it's enough to dig into the code a bit:
\Yii::$container->get - the second parameter - the parameters that are passed to the constructor (Yii also supplements them with dependencies).
Inside the container calls the php.net/manual/ru/reflectionclass.newinstanceargs.php
method
Accordingly, judging by the documentation of this method, you need to write
$value = \Yii::$container->get(PageValue::class, [$country, $value]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question