调用成员函数record_count()null codeigniter
尝试从包含成员列表的数据库设置一些分页。我有一个查询返回结果,但我无法将其纳入我在互联网上找到的分页示例。现在,当我尝试加载我的成员列表时,我得到一个对null成员函数record_count()的调用。以下是代码。调用成员函数record_count()null codeigniter
型号
public function count_members()
{
return $this->db->count_all("Users");
}
public function getMembers($limit, $start)
{
$this->db->limit($limit, $start);
$query = $this->db->get("users");
if ($query->num_rows() > 0){
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
/*if ($id == null) {
$query = $this->db->get('users');
}else{
$query = $this->db->get_where('users', ['id' => $id]);
}
return $query->result(); */
}
查看
<h1>Member Listing</h1>
<table border="1" align="center">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>Status</th>
<th>Last Login</th>
<th>Delete</th>
<th>Write Up</th>
<thead>
<tbody>
<?php foreach ($members as $_key => $_value): ?>
<tr>
<td><?=$_value->first_name?></td>
<td><?=$_value->last_name?></td>
<td><?=$_value->email?></td>
<td><?=$_value->status?></td>
<td><?=$_value->last_login?></td>
<td><a href="<?=site_url("admin/delete_member/{$_value->id}");?>">[X]</a></td>
</tr>
<?php endforeach;?>
<?php echo $links; ?></p>
</tbody>
</table>
<a href="<?php echo base_url(); ?>admin/home">Back to Dashboard</a>
控制器
public function view_members()
{
$this->load->model('Users_model');
$config = array();
$config["base_url"] = base_url() . "admin/view_members";
$config["total_rows"] = $this->Users->record_count();
$config["per_page"] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->Users->getMembers($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
//$this->data['members'] = $this->Users_model->getMembers();
$this->load->view('admin/inc/admin_header');
$this->load->view('admin/view_members', $this->data);
$this->load->view('admin/inc/admin_footer');
}
个错误信息 一个PHP错误遇到
严重性:注意
消息:未定义的属性:管理员:: $用户
文件名:控制器/ admin.php的
行号:217
致命错误:调用第217行的G:\ xampp \ htdocs \ highball061516 \ application \ controllers \ Admin.php中的null成员函数count_members() A PHP错误遇到
严重性:错误
消息:调用一个成员函数count_members()上的空
文件名:控制器/ admin.php的
行号:217
在代码点火器组态中,$config["total_rows"]
参数需要数据库中存在的记录总数。在你的代码中,它得到这个计数形式是一个在模型中不存在的函数。它应该从count_members
取而代之。以下是更新的控制器代码:
public function view_members()
{
$this->load->model('Users_model');
$config = array();
$config["base_url"] = base_url() . "admin/view_members";
// Code modified here
$config["total_rows"] = $this->Users_model->count_members();
$config["per_page"] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->Users->getMembers($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
//$this->data['members'] = $this->Users_model->getMembers();
$this->load->view('admin/inc/admin_header');
$this->load->view('admin/view_members', $this->data);
$this->load->view('admin/inc/admin_footer');
}
仍然给我的错误消息现在 – David
尝试。对'count_members'的引用之前是错误的。更新的代码... –
包括完整的错误消息 –