I have a controller class (OpenCart) Controller (for example: catalog / controller / product / product.php), the code looks like this:
class ControllerProductProduct extends Controller {
public function index() {
$this->response->setOutput($this->render());
}
}
there is an expression of type $this->response->setOutput($this->render());. I know what this expression is used for, but I'm very confused about how it works.
$thisrefers to the current ie class ControllerProductProduct, this means that the object $this->responsemust exist either in ControllerProductProductor in its parent class Controller. But this is not so. This object does exist in the protected property of the parent class Controlleras Controller::registry->data['response']->setOutput(). Therefore, one should not say so:
$this->registry->data['response']->setOutput();
instead of $ This-> response-> setOutput ();
I also give a fragment of the class Controllerso you can think.
abstract class Controller {
protected $registry;
public function __construct($registry) {
$this->registry = $registry;
}
public function __get($key) {
return $this->registry->get($key);
}
public function __set($key, $value) {
$this->registry->set($key, $value);
}
}
, ? , ?
.