簡體   English   中英

帶鏈接的Codeigniter表生成

[英]Codeigniter Table Generation With links

我有來自模型的數據進入此控制器

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 Table類)(這是用舊方法手工完成的,在我看來):

<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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM