OpenCart调用其他控制器 [英] OpenCart Call Different Controller

查看:315
本文介绍了OpenCart调用其他控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义模块,现在想从checkout/cart调用add()函数.如何调用控制器和函数?

I have a custom module, and now want to call the add() function from checkout/cart. How do I call the controller and function?

我尝试了$this->load->controller('checkout/cart');,但这会返回致命异常.

I have tried $this->load->controller('checkout/cart'); but this returns a fatal exception.

我正在使用OpenCart v 1.5.6.4

I am using OpenCart v 1.5.6.4

推荐答案

在OpenCart 1.5.*中,getChild用于加载其他控制器.具体来说,它正在运行到所需控制器和功能的路由.例如,common/home将从common组/文件夹中加载home控制器.通过添加第三个选项,我们指定了一个函数.在这种情况下,为添加"-checkout/cart/add.

In OpenCart 1.5.*, getChild is used to load other controllers. Specifically, it is running a route to the desired controller and function. For example, common/home would load the home controller from the common group/folder. By adding a third option we specify a function. In this case, 'add' - checkout/cart/add.

class ControllerModuleModule1 extends Controller {
  protected function index() {
    ob_start();
    $this->getChild('checkout/cart/add');
    $this->response->output();
    $response = ob_get_clean();
  }
}

大多数控制器不返回或回显任何内容,而是在$this->response对象中指定要输出的内容.要获取正在渲染的内容,您需要调用$this->response->output();.在上面的代码中,$responsecheckout/cart/add回显的json字符串.

Most controllers don't return or echo anything, but specify what to output in the $this->response object. To get what is being rendered you need to call $this->response->output();. In the above code $response is the json string that checkout/cart/add echos.

这篇关于OpenCart调用其他控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆