我正在尝试创建一个用户页面,我可以在其中显示一个表,其中包含从数据库中获取的用户数据。当我运行该文件时,我收到了404错误。如果您能查看我的代码,我将非常感激。
display_user.php
<?php
class display_user extends CI_Controller
{
public function index()
{
//load the database
$this->load->database();
//load the model
$this->load->model('DisplayModel');
//load the method of model
$data['h']=$this->select->select();
//return the data in view
$this->load->view('user_view', $data);
}
public function signin()
{
//$this->load->view('includes/header');
$this->load->view('user_view');
//$this->load->view('includes/footer');
}
public function validate()
{ $this->load->helper('email');
$this->load->library('form_validation');
$this->load->model('admin_model');
$query=$this->DisplayModel->signin_control();
if($query)
{ $admin_id = $this->DisplayModel->get_admin_id_from_username();
$admin = $this->DisplayModel->get_admin($employee_id);
$data = array('id'=>$employee_id, 'email' =>$this->input->post('email') , 'is_logged_in'=>true);
$this->session->set_userdata($data);
$this->load->view('admin_view',$employee);
}
else
{
$this->index();
}
}
public function signup()
{
$this->load->view('view_signup',array('error' => ' ' ));
}
}
?>
DisplayModel.php
<?php
class DisplayModel extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//we will use the select function
public function select()
{
//data is retrive from this query
$query = $this->db->get('employee');
return $query;
}
function signin_control()
{
$this->db->where('email',$this->input->post('email'));
$this->db->where('password',$this->input->post('password'));
$query=$this->db->get('employee');
if($query->num_rows()==1)
return $query;
}
public function get_employee_id_from_username()
{
$email=$this->input->post('email');
$this->db->select('id');
$this->db->from('employee');
$this->db->where('email', $email);
return $this->db->get()->row('id');
}
public function get_employee($employee_id)
{
$this->db->from('employee');
$this->db->where('id', $employee_id);
return $this->db->get()->row();
}
}
user_view.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
/* Remove the navbar's default margin-bottom and rounded borders */
.navbar {
margin-bottom: 0;
border-radius: 0;
}
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
.row.content {height: 450px}
/* Set gray background color and 100% height */
.sidenav {
padding-top: 20px;
background-color: #f1f1f1;
height: 100%;
}
/* Set black background color, white text and some padding */
footer {
background-color: #555;
color: white;
padding: 15px;
}
/* On small screens, set height to 'auto' for sidenav and grid */
@media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;}
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Kreatx</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Contacts</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Log Out</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid text-center">
<div class="row content">
<div class="col-sm-2 sidenav">
<img src="../../images/user.png" class="img-thumbnail" alt="User" width="304" height="236">
<ul>
</ul>
</div>
<div class="col-sm-8 text-left">
<h1>Welcome <strong>$employee_emer<strong>!</h1>
<hr>
<table border="1">
<tbody>
<tr>
<td><strong>Employee Id</strong></td>
<td><strong>Username</strong></td>
<td><strong>Password</strong></td>
<td><strong>Employee Name</strong></td>
<td><strong>Employee Surname</strong></td>
<td><strong>Address</strong></td>
<td><strong>Email</strong></td>
<td><strong>Department ID</strong></td>
</tr>
<?php
foreach ($h->result() as $row)
{
?><tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->username;?></td>
<td><?php echo $row->password;?></td>
<td><?php echo $row->employee_emer;?></td>
<td><?php echo $row->mbiemer;?></td>
<td><?php echo $row->adresa;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->id_departament;?></td>
</tr>
<?php }
?>
</tbody>
</table>
</div>
</br>
</div>
<div class="col-sm-2 sidenav">
<a href="<?php echo base_url()."index.php/display_user/index"; ?>" class="btn btn-primary" >Update Profile </a>
</br></br></br>
<a href="<?php echo base_url()."index.php/chat/index"; ?>" class="btn btn-primary" > Chat </a>
</br></br></br>
</div>
</div>
</div>
<footer class="container-fluid text-center">
<p><a href="http://www.kreatx.com/">Kreatx</a></p>
</footer>
</body>
</html>