Opencart – 在任何地方访问文档类

huangapple go评论70阅读模式
英文:

Opencart - Access document class in every where

问题

在 "catalog/controller/product.php" 中,我使用以下代码存储了一些数据:

$this->document->setSomeData("data");

我需要在 "system/library/response.php" 中使用以下代码来读取数据:

$this->document->getSomeData

但是在那里无法访问 document 类。我该怎么办?

英文:

I stored some data in "catalog/controller/product.php" OC v2.0.3.1 by using

> $this->document->setSomeData("data");

I need to read the data in "system/library/response.php" by using

> $this->document->getSomeData

But the document class is not reachable there. what can i do?

答案1

得分: 0

你可以将 $registry 传递给系统/framework.php 中的响应类,如下所示:

$response = new Response($registry);

在响应类中添加:

private $registry;
public function __construct($registry){
    $this->registry = $registry;
}

使用:

$document = $this->registry->get('document');
$document->setSomeData("data");
英文:

You can pass $registry into response class in your system/framework.php like this:

$response = new Response($registry);

In your response class add:

private $registry;
public function __construct($registry){
    $this->registry = $registry;
}

use:

$document = $this->registry->get('document');
$document->setSomeData("data");

huangapple
  • 本文由 发表于 2023年5月29日 20:17:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定