如何在codeigniter框架中生成的表的标记中添加属性

时间:2015-06-25 05:39:13

标签: php codeigniter

<?php
//setting table headings
$this->table->set_heading('Report Id','Patient Name','Reg date', 'Test code', 'Actions');

//defining table template
$tmpl = array('table_open' => '<table data-toggle="table" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true"  data-pagination="true" data-sort-name="date" data-sort-order="desc" data-show-export="true">', 'heading_cell_start' => '<th data-sortable="true">',);

$this->table->set_template($tmpl);
//generating table
echo $this->table->generate($reports);
?>

这会生成一个表,我想为标记添加一些属性,比如

<th data-field="reportid" data-sortable="true">Report Id</th>
<th data-field="patientname" data-sortable="true">Patient Name</th>
<th data-field="date" data-sortable="true">Reg date</th>

如何添加这些---- data-field="reportid" data-sortable="true" ---属性?

1 个答案:

答案 0 :(得分:2)

在模型中

public function get_product()
    {
        $sql = $this->db->query("SELECT * FROM tbale_name ");
        $result = $sql->result_array();
        return $result;
    }

在控制器中

$data['table'] = $this->Model_Name->get_product();

$this->load->view('admin/product',$data);//pass data to view

在视图中

<table data-toggle="table" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true"  data-pagination="true" data-sort-name="date" data-sort-order="desc" data-show-export="true">
    <tr>
        <th data-field="reportid" data-sortable="true" class="text-center">Report Id</th>
        <th data-field="patientname" data-sortable="true" class="text-center">Patient Name</th>
        <th data-field="date" data-sortable="true" class="text-center">Reg date</th>
        <th data-field="***" data-sortable="true" class="text-center">Test code</th>//set your data in (***)
        <th data-field="***" data-sortable="true" class="text-center">Actions</th>//set your data in (***)
    </tr>
    <?php
        foreach ( $table as $new_table )
        {
            ?>
            <tr>
                <td><?php echo $new_table['id']?></td>
                <td><?php echo $new_table['name']?></td>
                <td><?php echo $new_table['date']?></td>
                <td><?php echo $new_table['code']?></td>
                <td><?php echo $new_table['action']?></td>
            </tr>
        <?php
        }
    ?>
</table>