簡體   English   中英

致命錯誤:調用成員函數

[英]Fatal error: Call to a member function

我需要幫助調試我的代碼。 我是新的PHP和我目前正在使用codeigniter框架。 我試圖將我的數據庫表的內容顯示到我的頁面

/controllers/users.php

$<?php

class Users extends CI_Controller{

    function __Users(){

    // load controller parent
    parent::__Controller();

    // load 'Users' model
    $this->load->model('Users');
    }

    function index(){

    $data['users']=$this->Users->getUsersWhere('userid <',5);
    $data['numusers']=$this->Users->getNumUsers();
    $data['title']='Displaying user data';
    $data['header']='User List';

    // load 'users_view' view
    $this->load->view('users_view',$data);
    }
}
?>

/models/users.php

$<?php

class Users extends CI_Model{

function __Users(){

// call the Model constructor

parent::__CI_Model();

// load database class and connect to MySQL

$this->load->database();

}

function getAllUsers(){

$query=$this->db->get('admin_user');

if($query->num_rows()>0){

// return result set as an associative array

return $query->result_array();

}

}

function getUsersWhere($field,$param){

$this->db->where($field,$param);

$query=$this->db->get('admin_user');

// return result set as an associative array

return $query->result_array();

}

// get total number of users

function getNumUsers(){

return $this->db->count_all('admin_user');

}

}

?>

我有這個錯誤

致命錯誤:在第16行的C:\\ xampp \\ htdocs \\ printone \\ application \\ controllers \\ users.php中的非對象上調用成員函數getUsersWhere()

可能是什么錯?

您錯誤地命名了控制器構造函數,因此未調用它並且未加載模型。

更改

function __Users(){

function __construct(){

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM