升级 HTML 表格

文档

变更内容

  • 只改动了少量内容,例如方法名以及类的加载方式。

升级指南

  1. 在类中,将 $this->load->library('table'); 改为 $table = new \CodeIgniter\View\Table();

  2. 从这里开始,需要把每一行以 $this->table 开头的代码替换为 $table。例如:echo $this->table->generate($query); 会变为 echo $table->generate($query);

  3. HTML 表格类中的方法名可能略有不同。最重要的命名变化是由带下划线的方法名改为驼峰命名法。3.x 版本中的 set_heading() 现在名为 setHeading(),其他方法也是如此。

代码示例

CodeIgniter 3.x 版本

<?php

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

$this->table->set_heading('Name', 'Color', 'Size');

$this->table->add_row('Fred', 'Blue', 'Small');
$this->table->add_row('Mary', 'Red', 'Large');
$this->table->add_row('John', 'Green', 'Medium');

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

CodeIgniter 4.x 版本

<?php

$table = new \CodeIgniter\View\Table();

$table->setHeading('Name', 'Color', 'Size');

$table->addRow('Fred', 'Blue', 'Small');
$table->addRow('Mary', 'Red', 'Large');
$table->addRow('John', 'Green', 'Medium');

echo $table->generate();