我正在使用从我的数据库中提取的数据数组为我自动生成表的表类。

<强>模型

function get_reports_by_user_id($userid)
{
    return $this->db->get_where('ss2_report',array('userid' => $userid))->result_array();
}

<强>控制器

function index()
{
    echo $this->table->generate($this->mymodel->get_reports_by_user_id('1234'));
}

当我使用它时,控制器最终将移动到视图。这会生成表格,但我想添加一个字段的链接。例如,id列允许我链接到该报告的id的数据页面。我知道我可以手工输出老式的表格。然后我可以添加我想要的任何链接,但我希望能够尽可能多地使用自动生成。必须有一种方法可以像连接表格单元格那样常见。有没有人有任何想法?

修改

用户 Java PHP 主要位于下方。以下是使其有效的代码:

function get_reports_by_user_id($userid)
{
    $rows = $this->db->get_where('ss2_report',array('userid' => $userid))->result_array();

    foreach ($rows as $count => $row)
    {
        $rows[$count]['id'] = anchor('report/'.$row['id'],$row['id']);
    }
    return $rows;
}

我只需要用锚文本版本替换原始数组中的值。

有帮助吗?

解决方案

唯一的方法是,在函数 get_reports_by_user_id()中,您将遍历所有结果并将&lt; a href&gt; 标记添加到ID。像这样:

function get_reports_by_user_id($userid)
{
   $rows=$this->db->get_where('ss2_report',array('userid' => $userid))->result_array();
   foreach ($rows as $row)
   {
     $row->id=anchor('site.com/some_controller/some_function/'.$row->id,$row->id);
   }
   return $rows;
}

我不使用CodeIgniter的数据库库,所以我不确定它返回 $ rows 的格式,但上面的代码应该让你大致了解你需要做什么。

其他提示

一个想法可能是做一些像......

foreach ($row in $this->mymodel->get_reports_by_user_id('1234'))
{
    $row->id = anchor(site_url(array('report', 'user', $row->id)), $row->id);
    $this->table->add_row($row);
}
$this->table->generate();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top