模型:
class Pagination_model extends CI_Model
{
public function __construct() {
parent::__construct();
}
public function total_rows() {
return $this->db->count_all('recipe');
}
}
控制器:
function browse()
{
$this->load->library('pagination');
$this->load->library('table');
$config['base_url'] = 'http://localhost/Finals/index.php/login/browse';
$config['total_rows'] = $this->pagination_model->total_rows();
$config['per_page'] = 1;
$config['num_links'] = 10;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['records'] = $this->db->get('recipe', $config['per_page'], $this->uri->segment(3));
//echo "<pre>";print_r( $data['records'] );die;
$this->load->view('browse' , $data);
}
我的观点:
<html>
<head>
<title>blablabla</title>
<link href="../../css/default.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="header">
<div id="logo">
<h1><a href="#">grr</a></h1>
<h2>by chief</h2>
</div>
<div id="menu">
<ul>
<li class="first"><a href="#">Home</a></li>
<li><a href="#">My Profile</a></li>
<li><a href="#">My Recipes</a></li>
<li><a href="#">Browse Recipes</a></li>
<li><a href="#">Forum</a></li>
</ul>
</div>
</div>
<div id="content">
<div id="colOne">
<div class="post">
<div class="story">
<h2>Results:</h2>
<?php $this->table->generate($records); ?>
<?php $this->pagination->create_links(); ?>
</div>
</div>
</div>
</div>
<div id="footer">
<p>Copyright © </p>
</div>
</body>
</html>
这是从 print_r 返回的
[result_id] => mysqli_result Object
(
[current_field] => 0
[field_count] => 8
[lengths] =>
[num_rows] => 1
[type] => 0
)
[result_array] => Array
(
)
[result_object] => Array
(
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] => 1
[row_data] =>
它确实显示 1 行,可能是因为我的 1 per_page 限制。但是,为什么 row_data 是空的?它应该打印行值吗?
另外,即使 row_data 为空,当我输入 pagination create_links() 时,它应该至少显示正确吗?加载我的图书馆有什么问题吗?