【发布时间】:2014-03-05 13:01:33
【问题描述】:
如何将变量从控制器传递到 OpenCart 中的视图 (tpl) 文件?
我编写了一个自定义模块,所以我需要将返回的状态传递给视图。
下面是我加载 tpl 的控制器的一部分(它是一个巨大的功能,我只复制了所需的块)
$message = '';
if (isset($_POST['server_response'])) {
$message .= 'Server Says= ' . $_POST['server_response'] . "\n";
}
if (isset($_POST['output'])) {
$message .= 'Output= ' . $_POST['output'] . "\n";
$this->data['msg'] = $message;
$this->data['continue'] = $this->url->link('checkout/success');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/success.tpl')) {
$this->template = $this->config->get('config_template') . '/template/payment/success.tpl';
} else {
$this->template = 'default/template/payment/success.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
在我的 success.tpl 中,当我 echo $msg 时它说:
注意:未定义的变量:msg in C:\wamp\www\site\catalog\view\theme\hype\template\payment\success.tpl 第 16 行
谁能告诉我如何将 $msg 变量从控制器传递到 tpl?
【问题讨论】: