简体   繁体   English

Opencart 3:如何从自己的模块插入任何页面数据?

[英]Opencart 3: how to insert to any page data from own module?

I have own module with several fields.我有自己的模块,有几个字段。 I want to show this data in contact page and in the header.我想在联系页面和标题中显示这些数据。 How to connect this module for exemple to contact page controller?如何将此模块连接到例如联系页面控制器?

I have tried connect it like this:我试过这样连接它:

$data['mymodule'] = $this->load->controller('extension/module/mymodule');

But nothing.但什么都没有。 What I need to do?我需要做什么?

PS. PS。 My own mudule doesn't have model.我自己的mudule没有模型。 Cotroller and language only.仅控制器和语言。

As I thought, it's very easy to do.正如我所想,这很容易做到。 But I had to figure out exactly how.但我必须弄清楚到底是怎么做的。

First of all, we need to connect the modules model in the controller.首先,我们需要在控制器中连接模块模型。 Then connect the module that we need by ID.然后通过ID连接我们需要的模块。 At the end, according to the standard opencart scheme, we specify variables for outputting data from the array.最后,根据标准的 opencart 方案,我们指定用于从数组中输出数据的变量。

$this->load->model('setting/module');
$my_variable = $this->model_setting_module->getModule('module id');
$data['any_variable'] = $my_variable['any_variable'];

In the template在模板中

{{ any_variable }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM