Good evening!

Please tell me if I understand correctly:

$this->response->setOutput 

namely setOutput is a function? If so, where is it described in opencart? I did not find it on the Internet, I did not find it in opencart files (I was probably looking bad).

And here's what else interests:

 $this->response->setOutput(json_encode($json)); 

this line is similar to the exit(json_encode($json)); ?

exit(json_encode($json)); - I use it in a samopin engine, so I want to understand :)

    1 answer 1

    1: setOutput is a method of the Response class at the address `site / library / response.php.

    In general, almost everything that $ this-> and not from the current class is from the site / library /

    2: The method is responsible for transferring data (what and where):

     Это определение файла представления карты товара в контроллере и передача "в него" массива $data с данными товара. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) { $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/product.tpl', $data)); } else { $this->response->setOutput($this->load->view('default/template/product/product.tpl', $data)); } Это окончание метода autocomplete(), который реагирует на ввод в инпуте символов и возвращает значения для подстановки. $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); 

    In the first case, it works as a router, denoting which presentation file to choose for rendering the called route and transferring data to it. In the second case, it works as a return method (function), giving the data to the already drawn view file.

    • Those. the string $this->response->setOutput(json_encode($json)); essentially analogous - return json_encode($json); - Dima
    • Yes, I am of a sports interest changed to return, the return is the same. just this method is more functional and still works as a router in the opencard controllers in the index methods. - Kirill Korushkin
    • Not only at index, of course, but this is the most telling example. - Kirill Korushkin
    • Tell me, please, how to write another without OOP: $this->response->addHeader('Content-Type: application/json'); . - Dima
    • I can’t figure out how to embed this slice into my samopisny engine and where to send it) - Dima