代码点火器:将内置的CI功能添加到表中

时间:2015-12-08 15:20:07

标签: php codeigniter

我试图在Code Igniter中为表添加一些样式,我意识到CI有一个内置的表库来帮助实现这一目标。我不确定如何在我的具体实现中实现这一点。我想要整合这些内置功能:

$this->load->library('table');
$this->table->set_heading(array('Name', 'Color', 'Size'));

如何在特定实现中添加这些功能?

我有以下控制器:

    public function ecomma(){

        $this->load->model('report_model');
        $data ['query'] = $this->report_model->generate_ecomm_data_report();

        $this->load->view('report_view', $data);    
}

我的观点:

<table>
<tbody>

<?php foreach($query as $row): ?>
<tr>

    <td><?php echo $row->no_skus; ?></td>
    <td><?php echo $row->brand; ?></td>
    <td><?php echo $row->unique_models; ?></td>

</tr>
<?php endforeach; ?>

</tbody>
</table>

1 个答案:

答案 0 :(得分:1)

Using the Table library is quite easy. This example requires that Serializedreturns the results of a query. For example:

generate_ecomm_data_report()

Controller:

return $this->db->query('YOUR QUERY HERE');

One advantage to the Table library is that styling is quite easy using the template scheme of the class. For instance to add a CSS class to the header and to rows.

controller continues:

public function ecomma(){
    $this->load->library('table');
    $this->load->model('report_model');

    $query = $this->report_model->generate_ecomm_data_report();

View:

    $my_styles = array(
              "thead_open" => "<thead class='my_style'>",
              "row_start' => '<tr class='my-row-style'>");
    $this->table->set_template($my_styles);

    $this->table->set_heading(array('Name', 'Color', 'Size'));
    $data[table] = $this->table->generate($query);

    $this->load->view('report_view', $data);    
 }

The result will be a table structure like the one you create in the <?php echo isset($table) ? $table : "No Data"; ?> loop - only this one has style.