doutou7286 2014-03-05 13:01
浏览 70
已采纳

将变量从控制器传递到opencart中的视图

how to i pass variables from a controller to a view (tpl) file in OpenCart?

i have coded a custom module so i need to pass the the returned status to the view.

below is a part of my controller where i load the tpl (its a huge function, i have copied only the required block)

$message = '';

if (isset($_POST['server_response'])) {
$message .= 'Server Says= ' . $_POST['server_response'] . "
";
}

if (isset($_POST['output'])) {
$message .= 'Output= ' . $_POST['output'] . "
";

    $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());
}

in my success.tpl when i echo $msg it says:

Notice: Undefined variable: msg in C:\wamp\www\site\catalog\view\theme\hype\template\payment\success.tpl on line 16

can someone tell how can i pass the $msg variable from the controller to the tpl?

  • 写回答

3条回答 默认 最新

  • dongsuo9982 2014-03-05 13:08
    关注

    This should work.

    Try setting the variable outside of any of your if statements to a default value eg.

    $this->data['msg'] = 'test';
    

    To make sure that it's not any of the other logic such as the

    $_POST['output']
    

    that is faulty.

    At the moment you just set $message outside the if statement.

    When the if statement doesn't evaluate to true $this->data['msg'] will never get set.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 游戏盾如何溯源服务器真实ip?
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥50 win10链接MySQL
  • ¥15 抖音看过的视频,缓存在哪个文件