The database table "tb_bills" is populated but the table returns no data. And error is shown either. What could be the issue? what am I missing? Please check the code below, of the view, the model and the controller.
The table view.
<tbody>
<?php if(!empty($tb_bills)): ?>
<?php foreach($tb_bills as $bill): ?>
<tr>
<td><?php echo $bill['bill_No'];?></td>
<td><?php echo $bill['bill_Title'];?></td>
<td><?php echo $bill['bill_Type'];?></td>
<td><?php echo $bill['committee'];?></td>
<td><?php echo $bill['bill_sponsor'];?></td>
<td></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
The model
class RegisterModel extends Model{
protected $table = 'tb_bills';
protected $primaryKey = 'bill_Id';
protected $allowedFields = [
'bill_No',
'bill_Title',
'bill_Type',
'bill_Object',
'in_Capacity',
'bill_Sponsor',
'parliament',
'no_Clauses',
'session',
'committee',
'bill_Document',
'added_DateTime',
'updated_DateTime'
];
}
The controller
class RegisterController extends Controller {
public function index(){
$registerModal = new RegisterModal();
$data['bills'] = $registerModal->orderBy('id', 'DESC')->findAll();
return view('register-bill', $data);
}
}
CodePudding user response:
You could try
<?php foreach($bills as $bill): ?>
in your view
CodePudding user response:
try to insert a function in your model
public function getUsers()
{
return $this->findAll();
}
and then try this for your controller
$$registerModal = new RegisterModal();
$data['bills'] = $$registerModal->getUsers();