資料庫表“tb_bills”已填充,但該表未回傳任何資料。并且顯示錯誤。可能是什么問題?我錯過了什么?請檢查下面的代碼,視圖,模型和控制器。
表視圖。
<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>
該模型
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'
];
}
控制器
類 RegisterController 擴展控制器 {
public function index(){
$registerModal = new RegisterModal();
$data['bills'] = $registerModal->orderBy('id', 'DESC')->findAll();
return view('register-bill', $data);
}
}
uj5u.com熱心網友回復:
你可以試試
<?php foreach($bills as $bill): ?>
在你看來
uj5u.com熱心網友回復:
嘗試在您的模型中插入一個函式
public function getUsers()
{
return $this->findAll();
}
然后為你的控制器試試這個
$$registerModal = new RegisterModal();
$data['bills'] = $$registerModal->getUsers();
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/378629.html
