''); echo $this->table-6ren">
gpt4 book ai didi

php - 我该如何解决 "Object of class CI_Table could not be converted to string"?

转载 作者:搜寻专家 更新时间:2023-10-31 20:37:33 26 4
gpt4 key购买 nike

我是 CI 的新手,我按照网站上的教程进行操作,然后遇到了这个错误。这是我的 View 代码:

$data = array('table_open' => '<table class = "table-bordered">');

echo $this->table->set_template($data);

$col1 = array('data' => 'No');
$col2 = array('class' => 'col-md-4', 'data' => 'Agenda');
$col3 = array('class' => 'col-md-2', 'data' => 'Category');
$col4 = array('class' => 'col-md-2', 'data' => 'Date');
$option = array('class' => 'col-md-4', 'data' => 'Option');

echo $this->table->set_heading($col1, $col2, $col3, $col4, $option);
// echo $this->table->set_heading('No', 'Agenda', 'Category', 'Date', 'Option');
$no = 1;
if($agenda > 0) {
foreach($agenda as $ag) {

$item = $this->table->add_row($no++, $ag->agenda, $ag->agenda_cat, $ag->due_date,
anchor('agenda/edit' . $ag->id_agenda, 'Edit', array('class' => 'btn btn-info col-md-offset-1')) . " " .
anchor('agenda/delete' . $ag->id_agenda, 'Delete', array('class' => 'btn btn-danger'))
);
}
echo $item;
}

echo $this->table->generate();

table->set_heading()table->add_rows() 总是出错。

对于代码 echo $this->table->set_template($data);,它总是给出“1”作为输出。有人可以帮忙吗?

最佳答案

在 Controller 中加载库

$this->load->library('table');

Config/autoload.php

$autoload['libraries'] = array('table');

set_heading 函数总是返回对象。所以不使用 echo

所以你的代码(删除echo)

<?php
$data = array(
'table_open' => '<table class="table-bordered">');

$this->table->set_template($data);

$col1 = array('data' => 'No');
$col2 = array('class' => 'col-md-4', 'data' => 'Agenda');
$col3 = array('class' => 'col-md-2', 'data' => 'Category');
$col4 = array('class' => 'col-md-2', 'data' => 'Date');
$option = array('class' => 'col-md-4', 'data' => 'Option');

$this->table->set_heading($col1, $col2, $col3, $col4, $option);
// echo $this->table->set_heading('No', 'Agenda', 'Category', 'Date', 'Option');
$no = 0;

if(empty($agenda))
{
foreach($agenda as $ag)
{
$this->table->add_row($no++, $ag['agenda'], $ag['agenda_cat'], $ag['due_date'],
anchor('agenda/edit' . $ag['id_agenda'], 'Edit', array('class' => 'btn btn-info col-md-offset-1')) . " " .
anchor('agenda/delete' . $ag['id_agenda'], 'Delete', array('class' => 'btn btn-danger')));
}
}
else
{

}

codeigniter table

关于php - 我该如何解决 "Object of class CI_Table could not be converted to string"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31376643/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com