消息:为foreach()Codeigniter提供了无效的参数

时间:2019-03-28 02:14:36

标签: php codeigniter

我收到一条错误消息:视图中foreach()的参数无效。我想显示我的mysql表的所有数据,但我不断收到错误消息。我是Codeigniter的新手,我不知道如何解决此问题。这是我的代码。

视图中的代码(views / dashboardutama.php)

<table class="table table-striped projects" id="example1" border="1"> 
    <thead>
        <th style="padding:10px; text-align: center;" rowspan="2">STO</th>
        <th style="padding:10px; text-align: center;" colspan="3">Sales Non valid</th>
        <th style="padding:10px; text-align: center;" colspan="3">Sales HI</th>
    </thead>
    <tbody>
        <?php
        $i=1;
        foreach ($dashboardutama as $row) {
            ?>
            <tr>
                <td><?php echo $i; ?></td>
                <td><?php echo $row->$sto; ?></td>
                <td><?php echo $row->$salesnonv; ?></td>
                <td><?php echo $row->$saleshi; ?></td>
            </tr>
            <?php
            $i=$i+1;
        }
        ?>
    </tbody>
</table>

我的控制器(controller / dashboardutama.php)

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Dashboardutama extends CI_Controller {

public function index()
{
    $this->load->model('model_dashu');
    $data['dashboardutama'] = $this->model_dashu->get();
    $this->load->view('template/header');
    $this->load->view('dashboardutama', $data);
    $this->load->view('template/footer');
}


我的模型(models / model_dashu.php)

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Model_dashu extends CI_Model {

public function get(){
    $this->db->get('dashboardutama')->result();
}

我是一个初学者,所以我很难解决。谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您忘记了在get方法中返回结果。应该是:

public function get(){
    return $this->db->get('dashboardutama')->result();
}