Opencart的$ this-> config-> get('module_var_name') [英] Opencart's $this->config->get('module_var_name')
问题描述
我正在尝试自定义Opencart支付模块,我看到很多地方都在使用配置信息,但是找不到任何能够创建正在使用的变量的东西.我知道在管理页面中是否选择贝宝标准",我可以设置所有配置"信息,但是找不到在其下划线的模型",是否有模型,我希望创建一个新的配置设置,可在内部设置管理页面
管理页面如何知道要设置哪些变量?如果我将付款模块的管理员视图"更改为显示新设置,那么该设置会自动在目录中显示吗?
一些正在使用的配置数据的示例...
admin \ view \ template \ payment \ pp_standard.tpl(贝宝管理模板),允许设置测试模式"....
<tr>
<td><?php echo $entry_test; ?></td>
<td><?php if ($pp_standard_test) { ?>
<input type="radio" name="pp_standard_test" value="1" checked="checked" />
<?php echo $text_yes; ?>
<input type="radio" name="pp_standard_test" value="0" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="pp_standard_test" value="1" />
<?php echo $text_yes; ?>
<input type="radio" name="pp_standard_test" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } ?></td>
</tr>
catalog \ controller \ poayment \ pp_standard.php(贝宝目录控制器),使用上面的测试模式"来确定要命中哪个贝宝Web服务URL.
if (!$this->config->get('pp_standard_test')) {
$curl = curl_init('https://www.paypal.com/cgi-bin/webscr');
} else {
$curl = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
}
我原本希望在某个地方找到一个模型",并且在某个地方定义了"pp_standard_test",但是我什么也没发现,理解这一点的任何帮助将不胜感激.
P.S.在线上有很多建议,指出贝宝标准"支付模块是一个不错的起点,但很有可能,我们不会使用贝宝,这是我要弄清楚的原理.
在OpenCart管理中,admin/model/setting/setting.php
模型用于此类模块/扩展,其中仅密钥组名称和发布的数据提供来存储在setting
DB表中...(以及在多商店安装中也可以选择store_id
)
您可以检查 admin/controller/payment/
目录中的任何控制器,以了解如何使用此模型(pp_standard.php
,来自OC 1.5.5.1中的第10行):
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('pp_standard', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'));
}
这会将所有表单数据写入setting
DB表,而表单字段的名称用作填充其中的值的键.
因此,如果您致电
$this->config->get('<KEY>');
您可以获得为<KEY>
键设置的值.
I'm trying to customize an Opencart payment module, I see many places where config info is being used, but I cant find anything that creates what variables are in use. I know in the admin pages if I select 'paypal standard' I can set all the 'config' info, but I cant find the 'model' underlining it, is there a model, I wish to create a new config setting, settable inside the admin page
How does the admin page know which variables to set? If I change the admin 'view' for the payment module to show a new setting, will that setting automatically be available in the catalog?
example of some of the config data in use...
admin\view\template\payment\pp_standard.tpl (paypal admin template), allows 'test mode' to be set....
<tr>
<td><?php echo $entry_test; ?></td>
<td><?php if ($pp_standard_test) { ?>
<input type="radio" name="pp_standard_test" value="1" checked="checked" />
<?php echo $text_yes; ?>
<input type="radio" name="pp_standard_test" value="0" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="pp_standard_test" value="1" />
<?php echo $text_yes; ?>
<input type="radio" name="pp_standard_test" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } ?></td>
</tr>
catalog\controller\poayment\pp_standard.php (paypal catalog controller), uses above 'test mode' to determine which paypal Webservice URL to hit..
if (!$this->config->get('pp_standard_test')) {
$curl = curl_init('https://www.paypal.com/cgi-bin/webscr');
} else {
$curl = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
}
I was expecting to find a 'model' somewhere with 'pp_standard_test' defined somewhere, but I've found nothing, any help understanding this would be greatly appreciated.
P.S. There is much advice online stating that the 'paypal standard' payment module is a good place to start, but more than likely, we wont be using paypal, it's the principle I'm trying to figure out.
In OpenCart administration a admin/model/setting/setting.php
model is used for such a modules/extensions where only a key group name and the posted data is provided to be stored in the setting
DB table... (and optionally a store_id
in multistore installation as well)
You could check any of controllers in admin/controller/payment/
dir to see how is this model used (pp_standard.php
, from line 10 within OC 1.5.5.1):
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('pp_standard', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'));
}
This will write all the form data into the setting
DB table while form field's name is used as a key to the value filled within.
Thus if You call
$this->config->get('<KEY>');
You can get the value that is set for the <KEY>
key.
这篇关于Opencart的$ this-> config-> get('module_var_name')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!