简体   繁体   English

OpenCart从控制器传递到视图

[英]OpenCart passing from controller to view

New to OpenCart and am having issues. OpenCart的新手,遇到了问题。 I'm Trying to get the sum of a column from a table and display it on a page. 我正在尝试从表中获取列的总和并将其显示在页面上。 I've tried a few iterations of the following but always get an undefined variable error. 我尝试了以下迭代,但始终会得到未定义的变量错误。 I've been stuck on this for a while and am not sure what Im doing wrong. 我已经坚持了一段时间,不确定我在做什么错。

my model: 我的模特:

 public function getSum() {
        $amount_total = $this->db->query("SELECT FROM oct_donate SUM(amount) as amount_sum");
        $sums = $amount_total->row["amount_sum"];
        return $sums; 
        }

my controller: 我的控制器:

public function sum() {

        $data['total_sum']=$this->load->model('revenue/order')->getSum();      

    }

view: <?php echo $total_sum; ?> 查看: <?php echo $total_sum; ?> <?php echo $total_sum; ?>

The problem is in your controller code. 问题出在您的控制器代码中。 You have to load the model first and then call its method. 您必须先加载模型,然后调用其方法。 Update the code. 更新代码。

public function sum() {
  $this->load->model('revenue/order')
  $data['total_sum']=$this->model_revenue_order->getSum();
}

Also your query is not correct. 另外,您的查询不正确。 I think you missed to select columns. 我认为您错过了选择列的时间。 It should be 它应该是

$this->db->query("SELECT SUM(amount) as amount_sum FROM oct_donate");

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

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