Thirupathi
Joined: 01 Dec 2009 Posts: 116
|
Posted: Sat Feb 06, 2010 6:43 am Post subject: Pagination using codeigniter |
|
|
Hi Friends I have started php framework recently.I have done one sample application.In my application i have done the pagination with some smart work so now i would like to share my knowledge with you.
test.php:save this file in controllers folder.
<?php
class Test extends Controller{
function Test(){
parent::Controller();
$this->load->helper(array('form', 'url'));
$this->load->helper('url');
$this->load->database();
}
function index(){
$this->load->model('test_model');
$data = $this->test_model->general();
$data['query'] = $this->test_model->getProperties();
// load pagination class
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/test/index/';
$config['total_rows'] = $this->db->count_all('properties');
$config['per_page'] = '4';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
//load the model and get results
$this->load->model('test_model');
$data['results'] = $this->test_model->getProps($config['per_page'],$this->uri->segment(3));
// load the HTML Table Class
$this->load->library('table');
$this->load->view('testpageview',$data);
}
}
test_model.php::Save this file in model folder
<?php
class test_model extends Model{
function __construct(){
parent::Model();
$this->load->helper(array('url','html','form'));
}
function getProps($num, $offset) {
$query = $this->db->get('properties', $num, $offset);
return $query;
}
}
?>
testpageview.php::Save this file in views folder:
<html>
<body>
<?php echo $this->pagination->create_links(); ?>
<?php echo $this->table->generate($results); ?>
</body
</html>
That's it .....
I think it might be helpful for you.
Thanks and Regards,
Thirupathi.J |
|