笨表生成的链接
问题描述:
我已经从我的模型来到这个控制器数据笨表生成的链接
function index() {
$this->load->model('work_m');
$data = array();
$config['base_url'] = base_url().'index.php/work/index/';
$config['total_rows'] = $this->db->count_all('work');
$config['per_page'] = '10';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['result'] = $this->work_m->get_records($config['per_page'],$this->uri->segment(3));
$data['title'] = 'Page Display';
$data['content'] = 'todo/work_display';
$this->load->view('template3', $data);
}
我需要创建一个表(使用HTML表格类),在单元格中的以下链接(这是通过按照旧的方式,并在我看来):
<td width="8%"><?php echo anchor("work/fill_form/$row->id", $row->id);?></td>
<td width="10%"><?php echo $row->date; ?></td>
<td width="20%"><?php echo $row->title; ?></td>
<td width="47%"><?php echo $row->item = $this->typography->auto_typography($row->item);
如何将数据转换回控制器以便能够使用表生成方法?使用“通常”的php方法创建一个可怕的表格。
答
要使用CodeIgniter的表类,这里有一个如何你可以使用它的一个例子:
//-- Table Initiation
$tmpl = array (
'table_open' => '<table border="0" cellpadding="0" cellspacing="0">',
'heading_row_start' => '<tr class="heading">',
'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 class="alt">',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
);
$this->table->set_template($tmpl);
$this->table->set_caption("TABLE TITLE");
//-- Header Row
$this->table->set_heading('ID', 'Date', 'Title', 'Item');
//-- Content Rows
foreach($rows as $index => $row)
{
$this->table->add_row(
anchor("work/fill_form/$row->id", $row->id),
$row->date,
$row->title,
$this->typography->auto_typography($row->item)
);
}
//-- Display Table
$table = $this->table->generate();
echo $table;
非常感谢你。在制表原始数据时使用表类,但不知道如何放置链接,从而更改原始数据库数据。 再一次,非常感谢 – Brad 2009-11-04 01:28:44
但是我确实改变了“foreach($ rows as $ index => $ row)” 为“foreach($ result as $ row)”,因为$ resut是我在控制器中使用的。一切都很好 – Brad 2009-11-04 03:01:57
不客气。 此外,我在视图中而不是在控制器中的表代码(上面),因为它们是演示文稿的一部分。 – 2009-11-04 03:17:19