Codeigniter生成html表(尝试获取无对象的属性)
我正在尝试生成一个表格来显示我的网站查询,并添加一个包含每个查询的链接(操作)的列。
创建表后,我收到以下错误:
Message: Trying to get property of non-object (line 55)
我的控制器如下:
$this->table->set_heading('ID', 'Name', 'Surname', 'Email', 'Phone','Message','Date','Actions');
$enquiries = $this->contact_model->get_table_enquiries($per_page,$offset);
foreach($enquiries as $row) {
$links = anchor('admin/enquiries/edit/' ,'Edit');
$links .= anchor('admin/enquiries/delete/', 'Delete');
$this->table->add_row(
$row->id, //line 55
$row->first_name,
$row->last_name,
$row->email_address,
$row->phone_number,
$row->message,
$links
);
}
$viewdata['enquiries_table'] = $this->table->generate();
模型中获取结果的函数:
function get_table_enquiries($per_page,$offset)
{
$this->db->order_by('date','desc');
$query=$this->db->get('contact',$per_page,$offset);
return $query;
}
如何让我的 foreach 循环工作并创建必要的行并附加链接???
为什么我会收到错误消息?
I am trying to generate a table to display my websites enquiries and add a column containing links(actions) for each of the enquiries.
Upon creating my table I am receiving the following error:
Message: Trying to get property of non-object (line 55)
My controller is as follows:
$this->table->set_heading('ID', 'Name', 'Surname', 'Email', 'Phone','Message','Date','Actions');
$enquiries = $this->contact_model->get_table_enquiries($per_page,$offset);
foreach($enquiries as $row) {
$links = anchor('admin/enquiries/edit/' ,'Edit');
$links .= anchor('admin/enquiries/delete/', 'Delete');
$this->table->add_row(
$row->id, //line 55
$row->first_name,
$row->last_name,
$row->email_address,
$row->phone_number,
$row->message,
$links
);
}
$viewdata['enquiries_table'] = $this->table->generate();
And the function in the model that gets the results:
function get_table_enquiries($per_page,$offset)
{
$this->db->order_by('date','desc');
$query=$this->db->get('contact',$per_page,$offset);
return $query;
}
How can I get my foreach loop to work and create the necessary rows and append the links???
Why am I receiving the error message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你需要尝试
I think you need to try