英文:
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");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论