更新 - 我有桌子出现,问题是我有一个css文件,其中包括display:none;用于表格样式。
我正在创建一个管理面板,显示系统中的当前成员。我创建了一个从数据库中检索数据的表。问题是出于某种原因,表格没有显示在页面上。我已经通过在页面中添加一些文本进行了实验,并且显示了文本,但由于某种原因,当我添加表格时,它没有显示?每当我删除控制器中的header.php文件时都会出现该表,但是当我添加它时,该表不会显示在视图中?
模型
<?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();
}
}
}
?>
控制器
<?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');
}
}
?>
查看
<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">
答案 0 :(得分:1)
您好首先检查一下您是否获得数据
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);
}
答案 1 :(得分:0)
如果您没有使用页脚,则文件admin_view应关闭来自&#39;标题&#39;的打开标记。 (</div></body></html>
)渲染得很好。
我还建议您打开萤火虫或devtools并检查桌子是否存在。如果没有,请在加载&#39;标题后尝试回复某些内容。检查控制器是否真的加载了&#39; admin_view&#39;文件。
仅供参考:模型的一部分:
$num_data_returned = $query->num_rows;
if ($num_data_returned < 1) {
echo "No data in database";
exit();
}
永远不会被访问(之前有&#39;返回&#39;)。希望它有所帮助!