S
S
Serge Tkach2017-01-16 13:37:53
opencart
Serge Tkach, 2017-01-16 13:37:53

How to connect a subcontroller in the controller in OpenCart 2 and pass data to it?

The OC has the following options for including a subcontroller:
$data['header'] = $this->load->controller('common/header');
$this->getChildController('checkout/simplecheckout_customer/update_session');
In both cases, the controller or one of the controller methods is loaded without passing data.
How to make it possible to pass some data to the subcontroller?
All that comes to my mind is the use of global variables.
$GLOBALS['var'] = 'test_var';
$this->load->controller('extension/module/mod/fucntion');
unset($GLOBALS['var']);
What are the alternatives?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
opencart-russia, 2017-01-26
@opencart-russia

somewhere....
in controller /product/my_module.php

public function index($arg) {
.....
$cat_id = $arg['category_id'];

E
Egor, 2017-01-16
@egormmm

The second parameter in this->load->controller is to pass an array, where the key values ​​will become the names of the variables.

A
Anatoly Ivanov, 2017-03-02
@apeks

What about creating a library with the right methods and calling it in the right places?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question