我已经对CodeIgniter进行了分页,它将我的数据库中的结果列为,标题,内容,价格和postid。我想知道如何将显示的内容(标题,内容,价格)显示为链接(
function index()
{
$this->load->library('pagination');
$this->load->library('table');
$this->table->set_heading('postid', 'The Title', 'The Content', 'Price');
$config['base_url'] = 'http://localhost/ganbaru/index.php/site/index';
$config['total_rows'] = $this->db->get('posts')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$posts['records'] = $this->db->get('posts', $config['per_page'], $this->uri->segment(3));
$this->load->view('site_view', $posts);
}
这是视图代码
</head>
<body>
<div id="container">
<h1>Super Pagination with CodeIgniter</h1>
<?php echo $this->table->generate($records); ?>
<?php echo $this->pagination->create_links(); ?>
</div>
</body>
</html>
答案 0 :(得分:3)
更新抱歉不太明白
我没有使用过表库,但你可以创建循环,只需使用类似的东西输出链接:
在控制器中:
$query = $this->db->get('posts', $config['per_page'], $this->uri->segment(3));
$posts["records"] = $query->result_array();
在视图文件中:
</head>
<body>
<div id="container">
<h1>Super Pagination with CodeIgniter</h1>
<table>
<?php foreach($records as $record) { ?>
<tr>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["id"]; ?></a></td>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["title"]; ?></a></td>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["content"]; ?></a></td>
</tr>
<?php } ?>
</table>
<?php echo $this->pagination->create_links(); ?>
</div>
</body>
</html>
我没有对此进行过测试,并且比原始代码更难看,但会为您提供更直接的控制。&gt;
如果我理解正确
我看不到你echo
的位置或存储$this->pagination->create_links();
的结果,这就是从库中产生分页输出以及显示链接所需要显示的内容。但正如您所指出的那样,您不知道如何用标签包围输出。我尝试了用户指南中的示例:
$this->load->library('pagination');
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = '200';
$config['per_page'] = '20';
$this->pagination->initialize($config);
echo $this->pagination->create_links();
它产生了:
<strong>1</strong>
<a href="http://example.com/index.php/test/page/20">2</a>
<a href="http://example.com/index.php/test/page/40">3</a>
<a href="http://example.com/index.php/test/page/20">></a>
<a href="http://example.com/index.php/test/page/180">Last ›</a>
确实有标签。因此,您应该查看用户指南中的示例,并将分页输出存储为posts
下的变量,以便您可以在页面上显示它。例如$posts["pagination"] = $this->pagination->create_links();
然后使用echo $pagination
将其显示在页面上。
文档位于 - http://codeigniter.com/user_guide/libraries/pagination.html - 因此您可以快速阅读所有选项。
希望有帮助...
答案 1 :(得分:0)
CI table class的功能非常有限。
你可能能够达到你想要的效果:
$table_heading = array(
'<a href="some_link">Title</a>',
'<a href="some_link/foo">Price</a>');
$this->table->set_heading($table_heading);
这将使您直接控制标题行中的任何内容。这是未经测试但应该有效。
Johann建议的另一个选项是手动创建表格,这当然会让你100%控制输出。