我在CodeIgniter方面非常新手,并正在练习。我现在正在开发一个简单的Codeigniter应用程序,仅供练习。我在数据库中有银行和其分支机构。我只想显示带有其银行名称的分支机构。分支机构正在显示,但在控制器获取银行时,会出现此错误。我在SO尝试了这些链接,但没有找到有效的方法。
"A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object"
in Line Number: 85 and 91
这是我的控制器
function ShowBranchList() {
$branch_list = $this->FD_Model->get_all_branches();
$get_bank = $this->FD_Model->get_bank_by_branch($branch_list->bankid); //This is Line Number 85
if($branch_list ){
$data = array(
'pagetitle' => 'Branch List View',
'branch_list_data' => $branch_list,
'br_bank' => $get_bank['bank_name'],//This is Line Number 93
);
}
模型
/*function for getting all branches*/
function get_all_branches() {
$this->db->order_by( $this->brid, $this->order );
return $this->db->get( $this->brtable )->result();
}
/*function for getting banks by branches*/
function get_bank_by_branch( $id ) {
$this->db->where( $this->bid, $id);
return $this->db->get( $this->banktable )->row();
}
最后,这是我的“视图”。
foreach ($branch_list_data as $branch_list)
{
<?php echo $branch_list->brname ?>
<?php echo $br_bank; ?>
}
请问有人知道这个问题吗?
更新
当我尝试查看查询时
echo $this->db->last_query();
结果
从
tbl_bankmaster
中选择所有bid
为空的数据。
值 $branch_list->bankid
为 null
。当我硬编码一些值时,视图页面会显示而没有任何错误。