Skip to Content
PHPCODE
CodeIgniter Fetching & Listing Articles in AdminPanel
codeigniter code / July 29, 2018

Fetching & Listing Articles in Adminpanel

Step 1 :-Create file Articlesmodel in Models
For Example
<?php
class Articlesmodel extends CI_Model
{
public function articles_list()
{
$user_id=$this->session->userdata(‘user_id’);
$query=$this->db
->select(‘title’)
->from(‘articles’)
->where(‘user_id’,$user_id)
->get();
return $query->result();
}
}
?>
Step 2 :- Create file admin in view
For Example
<?php
class Admin extends MY_Controller
{
public function dashboard()
{
$this->load->model(‘articlesmodel’,’articles’);
$articles=$this->articles->articles_list();
$this->load->view(‘admin/dashboard’,[‘articles’=>$articles]);
}
}
?>
Step 3 :- Create file Dashboard in view
<?php include_once(‘admin_header.php’);?>
<div class=”container”>
<table class=”table”>
<thead>
<th>Sr. No.</th>
<th>Title</th>
<th>Action</th>
</thead>
<tbody>
<?php if(count($articles)):?>
<?php foreach($articles as $article):?>
<tr>
<td>1</td>
<td>Article Title</td>
<td>
<a href=”#” class=”btn btn-primary”>Edit</a>
<a href=”#” class=”btn btn-danger”>Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php else:?>
<tr>
<td colspan=”3″>Not Record Found</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<?php include_once(‘admin_footer.php’);?>

PHPCODE © 2023