Pages

Friday, 11 May 2018

Pagination in Codeigniter

Controller.php


public function welcome(){



$config=[

'base_url' => base_url('admin/welcome/'),
'per_page' => 10,
'total_rows' => $this->loginmodel->num_rows(),
'full_tag_open' => "<ul class='pagination'>",
'full_tag_close' => "</ul>",
'first_tag_open' => "<li>",
'first_tag_close' => "<li>",
'last_tag_open' => "<li>",
'last_tag_close' => "</li>",
'first_link' => '<<',
'last_link' => '>>',
'next_tag_open' => "<li>",
'next_tag_close' => "</li>",
'prev_tag_open' => "<li>",
'prev_tag_close' => "</li>",
'num_tag_open' => "<li>",
'num_tag_close' => "</li>",
'cur_tag_open' => "<li class='active'><a>",
'cur_tag_close' => "</a></li>",
];

$this->load->library('pagination');
$this->pagination->initialize($config);
$articles = $this->loginmodel->articleList($config['per_page'],$this->uri->segment(3));

$this->load->view('admin/dashboard',['articles'=>$articles]);
}




Dashboard.php


<table>
<thead>
<th>Id</th>
<th>Article Title</th>
<th>Article Image</th>
<th>Edit</th>
<th>Delete</th>
</thead>
<tbody>
<?php if(count($articles)):?>
<?php foreach($articles as $art): ?>
<tr>
<td><?php echo $art->id;?></td>
<td><?php echo $art->article_title;?></td>
<td><img src="<?php echo $art->article_img;?>" height="50" width="50"></td>
<td><?php echo anchor('admin/editarticle/'.$art->id, 'Edit', 'class="btn btn-info"');?></td>
<td>
<?php echo anchor('admin/delarticles/'.$art->id, 'Delete', 'class="btn btn-danger"');?>

</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="3">Data Not Found</td>
</tr>
<?php endif;?>

</tbody>
</table>

<?= $this->pagination->create_links();   ?>

No comments:

Post a Comment