Search code examples
phpopencartopencart2.xopencart-3

Opencart - Access document class in every where


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?


Solution

  • 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");