从codeigniter加载我想要的表格

时间:2015-04-06 14:37:57

标签: php codeigniter

我对codeigniter很新,但到了那里。我已经通过以下代码加载了一个页面。我已经研究过如何从sql语句中生成一个html表,正如你所看到的那样,但是这样它就会在页面的顶部隐藏它。如何在评论中标记的点上对表格进行渲染?

routes.php文件

$route['users/list'] = 'users/listu';

控制器/ users.php

public function listu()
    {
        $this->load->library('table');

        $query = $this->db->query("SELECT * FROM users");

        echo $this->table->generate($query);

        $this->load->view('templates/header');
        $this->load->view('users/list');
        $this->load->view('templates/footer');
    }

视图/用户/ list.php的

<div class="row">
            <div class="col-lg-3 col-md-3 col-sm-12">

                <!-- Categories -->
                <div class="col-lg-12 col-md-12 col-sm-6">
                    <div class="no-padding">
                        <span class="title">Menu</span>
                    </div>
                    <div class="list-group list-categ">
                        <a href="item" class="list-group-item">Item</a>
                        <a href="item" class="list-group-item">Item</a>
                        <a href="item" class="list-group-item">Item</a>
                        <a href="item" class="list-group-item">Item</a>
                        <a href="item" class="list-group-item">Item</a>
                        <a href="item" class="list-group-item">Item</a>
                        <a href="item" class="list-group-item">Item</a>

                    </div>
                </div>
                <!-- End Categories -->

            </div>

            <div class="clearfix visible-sm"></div>

        <div class="col-lg-9 col-md-9 col-sm-12">
            <div class="col-lg-12 col-sm-12">
                <span class="title">List Users</span>
                    <!-- I want to put the table here -->
            </div>
        </div>

    </div>
</div>

1 个答案:

答案 0 :(得分:0)

我已经解决了

<强>控制器/ users.php

public function listu()
    {
        $this->load->library('table');

        $query = $this->db->query("SELECT firstname, surname, email FROM users");

        $data['table_users'] = $this->table->generate($query);

        $this->load->view('templates/header');
        $this->load->view('users/list', $data);
        $this->load->view('templates/footer');
    }

并在标记中:

<?php echo($table_users) ?>