像这样的普通表函数$this->table->generate()
会产生这样的结果:
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>one</td><td>two</td><td>three</td>
</tr>
</table>
我怎样才能生产出类似的东西
<table border="0" id="myTable" cellpadding="4" cellspacing="0">
像这样的普通表函数$this->table->generate()
会产生这样的结果:
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>one</td><td>two</td><td>three</td>
</tr>
</table>
我怎样才能生产出类似的东西
<table border="0" id="myTable" cellpadding="4" cellspacing="0">
你试过这个吗?
$tmpl = array ( 'table_open' =>
'<table border="1" cellpadding="2" cellspacing="1" id="YOUR_ID" class="mytable">' );
$this->table->set_template($tmpl);
echo $this->table->generate();
更新 1:
$tmpl = array (
'table_open' => '<table border="1" cellpadding="2" cellspacing="1" id="YOUR_ID" class="mytable">',
'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th>',
'heading_cell_end' => '</th>',
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
'row_alt_start' => '<tr>',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
);
$this->table->set_template($tmpl);
参考:https ://ellislab.com/codeigniter/user-guide/libraries/table.html
您可以使用set_template()
函数将table_open
值设置为您需要的输出。
$template = array('table_open' => '<table border="0" id="myTable" cellpadding="4" cellspacing="0">');
$this->table->set_template($template);