モデル:
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行が表示されます。しかし、なぜ row_data が空なのですか? 行の値を出力する必要がありますか?
さらに、row_data が空だったとしても、pagination create_links() を入力すると、少なくとも正しく表示されるはずですか? ライブラリの読み込みに問題はありますか?