user122938221
user122938221

Reputation: 33

Codeigniter - Bootstrap table not appearing in view?

UPDATE - I have got the table to appear, the problem was I had a css file which included display:none; for the table styling.

I am creating an admin panel which displays the current members in the system. I created a table which retrieves data from the database. The problem is for some reason, the table isn't showing up on the page. I have experimented by adding some text to the page, and the text appears, but for some reason when i add a table, it doesn't show? The table appears whenever i remove the header.php file in the controller but when i add that in, the table doesn't show in the view?

Model

<?php
class user_model extends CI_Model{

    public function getUser(){

        $this->db->select("userID, firstname, lastname, email, username, password, reg_time, activated, image");
        $this->db->from("users");
        $query = $this->db->get();

        return $query->result();

        $num_data_returned = $query->num_rows;
        if ($num_data_returned < 1) {
            echo "No data in database";
            exit();
        }
    }
}

?>

Controller

<?php
class Dashboard extends CI_Controller{
    public function __construct(){
        parent::__construct();
        $this->check_isvalidated();
        $this->load->model('user_model');

    }

    public function index(){
        $this->data['user'] = $this->user_model->getUser(); 
        $this->load->view('home/header'); /* header.php file which contains bootstrap css */
        $this->load->view('home/admin_view', $this->data);
    }   

    private function check_isvalidated(){
        if (! $this->session->userdata('validated')) {
            redirect('adminlogin');
        }
    }

    public function logout(){
        $this->session->sess_destroy();
        redirect('adminlogin');
    }



}

?>

View

<div class="col-xs-12" >
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="col-lg-12">

    <table>
        <caption>System Members</caption>
        <thead>
            <tr>
                <th>Firstname</th>
                <th>Lastname</th>
                <th>Email Address</th>
                <th>Username</th>
                <th>Password</th>
                <th>Registration Time</th>
                <th>Activated</th>
                <th>Image</th>
            </tr>

        </thead>
        <tbody>
            <?php foreach ($user as $usr) { ?>
                <tr>
                    <td><?=$usr->firstname?></td>
                    <td><?=$usr->lastname?></td>
                    <td><?=$usr->email?></td>
                    <td><?=$usr->username?></td>
                    <td><?=$usr->password?></td>
                    <td><?=$usr->reg_time?></td>
                    <td><?=$usr->activated?></td>
                    <td><?=$usr->image?></td>
                </tr>
            <?php } ?>
        </tbody>
    </table>
        </div>
        </div>
    </div>
</div>

header.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Panna Daily - Admin</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap.css"/>
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap-theme.css"/>
    <link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/site.css"/>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="<?php echo base_url(); ?>assets/js/jquery-2.2.0.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js"></script>
</head>
<body>
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <a class="navbar-brand" href="<?php echo site_url('Dashboard/index'); ?>">Admin Dashboard</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">

                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" data-toggle="dropdown" class="dropdown-toggle"><i class="glyphicon glyphicon-user"></i><b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="<?php echo site_url('Dashboard/logout'); ?>"><i class="glyphicon glyphicon-log-out"></i> Sign Out</a></li>
                        </ul>
                    </li>
                </ul>
            </div><!--/.navbar-collapse -->
        </div>
    </nav>
    <br/>
    <div class="container">

Upvotes: 1

Views: 735

Answers (2)

Divyesh
Divyesh

Reputation: 389

Hello first check here you get data or not

    public function index(){
            $this->data['user'] = $this->user_model->getUser(); 
            $this->load->view('home/header'); /* header.php file which contains bootstrap css */
print_r($this->data);
            $this->load->view('home/admin_view', $this->data);
        }

Upvotes: 1

JP. Aulet
JP. Aulet

Reputation: 4398

If you aren't using a footer, the file admin_view should close the opens tags from 'header' (</div></body></html>) to render well.

Also I suggest you to open the firebug or devtools and check if the table is there or not. If not, try to echo something after loading the 'header' to check if the controller really load the 'admin_view' file.

FYI: the part of the model:

    $num_data_returned = $query->num_rows;
    if ($num_data_returned < 1) {
        echo "No data in database";
        exit();
    }

Will be never accessed (there is a 'return' before it). Hope it helps!

Upvotes: 0

Related Questions