Codeigniter问题,我不知道我的MVC有什么问题

所以我不知道这是我的控制器还是CodeIgniter Framework中的模型出了什么问题,请提供帮助。我的表在我的视图中没有从数据库中获取数据。

我已经尝试了我在stackoverflow中看到的所有内容,但是我无法使其正常工作,但这是我的原始代码。

这是我的控制器

public function index(){

    $data['suppliers'] = $this->dashboard_model->readSupplier();
    $data['items'] = $this->dashboard_model->readItem();
    $data['users'] = $this->dashboard_model->readUser();
    $data['units'] = $this->dashboard_model->readUnit();
    $data['logs'] = $this->dashboard_model->readLogs();

            $this->global['pageTitle'] = 'Dashboard';
            $this->loadViews("pages/dashboard",$this->global,$data);

这是我的模型

class Dashboard_model extends CI_Model{

        function readSupplier(){
            $this->db->from('suppliers');
            $this->db->limit(5);
            $this->db->order_by('supplier_id','DESC');
            $query = $this->db->get();
            $result = $query->result();
            return $result;
        }

        function readItem(){
            $data = array(
                'categories.category_name','items.item_id','items.category_id','items.brand_name','items.model','items.serial','items.unit_price','items.status','items.location_id','suppliers.supplier_id','suppliers.supplier_name'
            );
            $this->db->select($data);
            $this->db->from('items');
            $this->db->join('categories','categories.category_id = 
            items.category_id','left');
            $this->db->join('suppliers','suppliers.supplier_id = 
            items.supplier_id','left');
            $this->db->limit(10);
            $this->db->order_by('item_id','DESC');
            $query = $this->db->get();

            $result = $query->result();
            return $result;
}

        function readUser(){
            $this->db->from('users');
            $this->db->limit(10);
            $this->db->order_by('userId','DESC');
            $query = $this->db->get();
            $result = $query->result();
            return $result;
        }

        function readUnit(){
            $data = array(
                'l.location_name','su.su_id','su.unit','su.motherboard','su.processor','su.ram','su.hdd','su.video_card','su.lan_card','su.power_supply','su.location_id','su.comment',);
            $this->db->select($data);
            $this->db->from('system_unit as su');
            $this->db->join('locations as l','l.location_id=su.location_id','left');
            $this->db->limit(10);
            $this->db->order_by('unit','DESC');
            $query = $this->db->get();
            $result = $query->result();
            return $result;
        }

        function readLogs(){

            $this->db->from('activities as a');
            $this->db->join('users as u','u.userId=a.userId','left');
            $this->db->limit(10);
            $this->db->order_by('userId','DESC');
            $query = $this->db->get();

            $result = $query->result();
            return $result;
    }
?>

这是我的视图

    <th>User ID</th>
    <th>Full Name</th>
    <th>Email</th>
    </thead>
    <tbody>
    <?php
        if(!empty($users)):
            foreach($users as $user): ?>
    <tr>
    <td><?php echo $user->userId; ?></td>
    <td><?php echo $user->firstname." ".$user->lastname; ?></td>
    <td><?php echo $user->email; ?></td>
    </tr>
           <?php endforeach;
           endif;
           ?>
blzhi 回答:Codeigniter问题,我不知道我的MVC有什么问题

问题出在您的控制器的方法中:loadViews

您可以通过此链接查看how to load view的方式。

我认为在模型中就可以了。因此,您需要检查方法loadViews。而且,如果您真的想看到一些结果,则可以替换下一个:

 $this->global['pageTitle'] = 'Dashboard';
 $this->loadViews("pages/dashboard",$this->global,$data);

使用

$this->load->view('pages/dashboard',$data);

注意:请阅读如何使用此方法load->view的第三个参数,它可以具有值truefalse,默认情况下为false。 / em>

,

我现在真正进入了它,现在我唯一遇到的问题是它给我有关readLogs函数的错误,但是如果我删除了readLogs函数,则所有表将显示其数据,但Log除外。历史。顺便说一下,这是错误。

发生数据库错误 错误编号:1052

order子句中的“ userId”列不明确

选择*从activitiesa,左usersu上,uuserId = a。{ {1}}按userId DESC LIMIT 10排序

文件名:E:/Xammp2/htdocs/cri-marc/system/database/DB_driver.php

行号:691

本文链接:https://www.f2er.com/3147959.html

大家都在问