I am a beginner in Codeigniter framework and I am also learning from youtube
In my admin.php code is
<?php
class Admin extends MY_Controller {
public function dashboard(){
$this->load->model('articlesmodel');
$articles = $this->articlesmodel->articles_list();
$this->load->view('admin/dashboard', ['articles'=> $articles]);
}
}
?>
And in my dashboard.php code is
<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-info">Edit</a>
<a href="" class="btn btn-danger">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php else:?>
<tr>
<td colspan="3">No Records Found</td>
</tr>
<?php endif;?>
</tbody>
</table>
I am fetching the articles from my database in table format, but the following error is presented: Undefined variable: articles in dashboard.php page