T
T
Timur2017-03-13 21:20:55
symfony
Timur, 2017-03-13 21:20:55

How to pass variables to the constructor in Symfony when creating an object via DI?

I'm just starting to learn symfony, and it's not clear to me how to create an object in it using DI by passing the necessary parameters to the constructor?
If in Yii2 I did this

$container->set('\app\components\SearchEngineInterface', '\app\components\SearchEngine');

//После чего мог делать что-то типа

$engine = $container->get('app\components\SearchEngineInterface', [$apiKey, $apiSecret], ['type' => 1]);
// Что эквивалентно: $engine = new \app\components\SearchEngine($apiKey, $apiSecret, ['type' => 1]);

I didn't find something like this in symfony, and I suspect that I didn't search well
. Is there something similar in SF?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2017-03-13
@XAKEPEHOK

But it doesn't make sense. At least in the implementation you showed. If I replace
on, for example,
where is the guarantee that the constructors of these classes will match?
And so, it looks like you need a factory symfony.com/doc/current/service_container/factorie...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question