【问题标题】:Codeigniter Table Generation With links使用链接生成 Codeigniter 表
【发布时间】:2010-12-11 23:42:16
【问题描述】:

我的模型中有数据进入这个控制器

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 方法会创建一个可怕的表。

【问题讨论】:

    标签: php html codeigniter html-table


    【解决方案1】:

    要使用 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;
    

    【讨论】:

    • 非常感谢。我在表原始数据时使用表类,但不知道如何放入链接从而更改原始数据库数据。再次,非常感谢你
    • 我确实将“foreach($rows as $index => $row)”更改为“foreach($result as $row)”,因为 $resut 是我在控制器中使用的。一切都很好
    • 不客气。另外,我在视图中而不是在控制器中有表格代码(上图),因为它们是演示的一部分。
    • 我把除了foreach部分和表格之外的所有东西都放在了控制器中。奇迹般有效。我想知道添加行是否不是要走的路,但并没有真正理解它
    • CodeIgniter 用户指南 (codeigniter.com/user_guide) 相当容易使用且不会出现新手问题。它的目录几乎涵盖了这个框架中的所有用法,你需要 2~3 个小时来完成每个主题,你就会彻底了解 CodeIgniter!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    • 2011-06-29
    • 1970-01-01
    相关资源
    最近更新 更多