O
O
Oleg Korniychuk2016-05-12 15:40:30
opencart
Oleg Korniychuk, 2016-05-12 15:40:30

How to call another controller method in OpenCart 1.5 from one controller?

In OpenCart 2.X I do like this:

//Файл admin/controller/catalog/product.php
$result = $this->load->controller('module/svitstyle/update', array('fields'=>$this->request->post, 'product_id'=>$this->request->get['product_id']));

That is, I launch the controller inside the controller, pass parameters to it and get a response. I can't figure out how to implement this in the old version. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Korniychuk, 2016-05-12
@isntlazy

Happened! We need to do the following:
In the controller that we call, we return the result as:

$this->response->setOutput(json_encode($api->result));

And in the controller that calls it, like this:
ob_start();
$this->getChild('module/svitstyle/update', array('fields'=>$this->request->post, 'product_id'=>$this->request->get['product_id']));
$this->response->output();
$response = ob_get_clean();
$result = json_decode($response);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question