I am new in cakephp 3. Now, I am fetching data from database which is successfully show all table data but I want to show 'No record found' message if table is empty. So, How can I do this ?Please help me.
Controller: PostsController
<?php
namespace App\Controller;
use App\Controller\AppController;
Class PostsController extends AppController {
Public function index(){
$this->set('data',$this->Posts->find('all'));
}
}
?>
Layout: Index.cpt
<div class="row">
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($data))
{
foreach($data as $row)
{
?>
<tr>
<td><?php echo $row->title; ?></td>
<td><?php echo $row->description; ?></td>
<td></td>
</tr>
<?php
}
}
else
{
echo '<p>No record found</p>';
}
?>
</tbody>
</table>
</div>