フレームワーク(OpenCart)コントローラークラス(カタログ/コントローラー/製品/製品.phpなど)があり、コードは次のようになります。
class ControllerProductProduct extends Controller {
public function index() {
//some code
$this->response->setOutput($this->render());
//some more code
}
}
のような表現があり$this->response->setOutput($this->render());
ます。この表現が何に使われるかは知っていますが、どのように機能するかについてはかなり混乱しています。
$this
現在のクラスを参照します。つまりControllerProductProduct
、$this->response
オブジェクトがいずれかControllerProductProduct
またはその親クラスに存在する必要があることを意味しますController
。しかし、そうではありません。このオブジェクトは、実際には親クラスの保護されたプロパティにController
として存在しController::registry->data['response']->setOutput()
ます。したがって、次のように言うべきではありません。
$this->registry->data['response']->setOutput();
$this->response->setOutput(); の代わりに
Controller
クラスのスニペットも提供しているので、アイデアを得ることができます。
abstract class Controller {
protected $registry;
//Other Properties
public function __construct($registry) {
$this->registry = $registry;
}
public function __get($key) {
//get() returns registry->data[$key];
return $this->registry->get($key);
}
public function __set($key, $value) {
$this->registry->set($key, $value);
}
//Other methods
}
この表現がどのように機能しているのかわかりませんか?これがどのように可能か考えていますか?
ありがとう。