Answer the question
In order to leave comments, you need to log in
How to extract an object from the Service Container depending on the argument?
How to do this
class Product {
private $container;
private $data;
public function __constructor( ServiceContainer $container ) {
$this->container = $container;
$this->data = $this->container->get('someotherservice')->getDataById( $ID );
}
}
// controller code
$ID = 123;
$product = $this->get('service.product'); // как передать туда ID?
Answer the question
In order to leave comments, you need to log in
You can't do that.
Or rather, it is possible, but this is a complete bad manners and an architectural mistake.
Inject someotherservice into the controller and call its getDataById method .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question