Php 在Codeigniter中找不到404页
我是CodeIgniter的新手,在为用户仪表板创建了新模型之后,除了管理员dashbaord之外,我还遇到了以下错误。如果有人能帮助我,那真是太好了。我检查了StackOverflow中以前的答案,但没有一个对我有帮助 我遇到以下错误 与错误相关的代码段如下所示 模型代码Php 在Codeigniter中找不到404页,php,mysql,codeigniter,Php,Mysql,Codeigniter,我是CodeIgniter的新手,在为用户仪表板创建了新模型之后,除了管理员dashbaord之外,我还遇到了以下错误。如果有人能帮助我,那真是太好了。我检查了StackOverflow中以前的答案,但没有一个对我有帮助 我遇到以下错误 与错误相关的代码段如下所示 模型代码 <?php //Details of queries whicha re used to interact with teh database class Queries extends CI_Model {
<?php
//Details of queries whicha re used to interact with teh database
class Queries extends CI_Model {
//Created a function with the name getRoles
public function getRoles() {
//Fetch the reocrds from the table
$roles = $this->db->get('tbl_roles');
if ($roles->num_rows() > 0) {
return $roles->result();
}
}
//Created a function with the name getColleges
//Used to list collge names in addcodmin view page
public function getColleges() {
//Fetch the reocrds from the table
$colleges = $this->db->get('tbl_college');
if ($colleges->num_rows() > 0) {
return $colleges->result();
}
}
public function registerAdmin($data) {
return $this->db->insert('tbl_users', $data);
}
//create function to check whther three is a admin or not...if not only
// that add admin button will be appered
public function checkAdminExist() {
$checkAdmin = $this->db->where(['role_id' => '1'])->get('tbl_users');
if ($checkAdmin->num_rows() > 0) {
return $checkAdmin->num_rows();
}
}
//Create function to check the entered email and password existance
public function adminExist($email, $password) {
$checkAdmin = $this->db->where(['email' => $email, 'password' => $password])->get('tbl_users');
if ($checkAdmin->num_rows() > 0) {
return $checkAdmin->row();
}
}
//Created function makeCollege and return value and
public function makeCollege($data) {
//if value is 0 - and 1 - if the data get inserted into the table
return $this->db->insert('tbl_college', $data);
}
//Created function register coadmin fot coadmin query called and passing data to the admin.php
//used insert method of the db class if inserted value 1 and if not value 0
public function registerCoadmin($data) {
return $this->db->insert('tbl_users', $data);
}
//qruery to display all the colleges and details in teh dashboard
public function viewAllColleges() {
//get data from differendt table and view them in one single table
$this->db->select(['tbl_users.user_id', 'tbl_users.email', 'tbl_college.college_id',
'tbl_users.username', 'tbl_users.gender', 'tbl_college.collegename',
'tbl_college.branch', 'tbl_roles.rolename']);
$this->db->from('tbl_college');
$this->db->join('tbl_users', 'tbl_users.college_id = tbl_college.college_id');
$this->db->join('tbl_roles', 'tbl_roles.role_id = tbl_users.role_id');
//get the details and return details
$users = $this->db->get();
return $users->result();
}
public function insertStudent($data) {
return $this->db->insert('tbl_student', $data);
}
public function getStudents($college_id) {
//select fields required to diaply from the college and the student table
$this->db->select(['tbl_student.id', 'tbl_college.collegename', 'tbl_student.studentname',
'tbl_student.gender', 'tbl_student.email', 'tbl_student.course']);
//Common fileds in the both the table
$this->db->from('tbl_student');
$this->db->join('tbl_college', 'tbl_college.college_id = tbl_student.college_id');
//Take only stuednts who has college id (Get the details of all the students with the college id of 3)
$this->db->where(['tbl_student.college_id' => $college_id]);
$students = $this->db->get();
return $students->result();
}
public function getStudentRecord($id) {
$this->db->select(['tbl_college.college_id', 'tbl_college.collegename',
'tbl_student.id', 'tbl_student.email', 'tbl_student.gender', 'tbl_student.studentname',
'tbl_student.course']);
$this->db->from('tbl_student');
$this->db->join('tbl_college', 'tbl_college.college_id = tbl_student.college_id');
$this->db->where(['tbl_student.id' => $id]);
$student = $this->db->get();
return $student->row();
}
public function upgradeStudent($data, $id) {
return $this->db->where('id', $id)
->update('tbl_student', $data);
}
public function removeStudent($id) {
return $this->db->delete('tbl_student', ['id' => $id]);
}
}
?>
控制器代码1
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Users extends MY_Controller {
public function dashbaord() {
$this->load->model('queries');
//$college_id=$this->session->userdata('college_id';
$students = $this->queries->getStudents($college_id);
$this->load->view('users',['students'=>$students]);
}
}
您试图访问的页面的url是什么?您是否有任何路由设置?我怀疑您尚未实现htaccess文件。尝试将index.php
包含在url中collegems/index.php/users/dashboard
@Presmelito已经添加了htacess,并且index.php已从url中隐藏。这是唯一不起作用的路由吗?您是如何到达那里的?您提交了任何表单吗?@Presmelito有2个用户角色,我以管理员和联合管理员的身份登录。当我以coadmin身份登录时,我进入此页面并出错。。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends MY_Controller {
public function index() {
//New function to display add admin button
//and commented the existing code of $this->load->view('home');
$this->load->model('queries');
$checkAdminExist = $this->queries->checkAdminExist();
$this->load->view('home', ['checkAdminExist' => $checkAdminExist]);
//
}
public function adminRegister() {
//loading teh queries model
$this->load->model('queries');
//Calling the getRoles function inside the roles
//$roles holds the data of 2 records availble in the roles table
$roles = $this->queries->getRoles();
// print_r($roles);
// exit();
// $this->load->view('register');
//Pass this to an register view in type of an array and pass the data to register view
$this->load->view('register', ['roles' => $roles]);
}
public function adminSignup() {
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('gender', 'Gender', 'required');
$this->form_validation->set_rules('role_id', 'Role', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confpwd', 'Password Again', 'required');
$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');
if ($this->form_validation->run()) {
$data = $this->input->post();
$data['password'] = sha1($this->input->post('password'));
$data['confpwd'] = sha1($this->input->post('confpwd'));
$this->load->model('queries');
if ($this->queries->registerAdmin($data)) {
$this->session->set_flashdata('message', 'Admin Registered Sucessfully');
return redirect("welcome/adminRegister");
} else {
$this->session->set_flashdata('message', 'Failed to Register Admin!');
return redirect("welcome/adminRegister");
}
// echo '<pre>';
// print_r($data);
// echo '<pre>';
// exit();
} else {
echo $this->adminRegister();
}
}
//Create new view for login function in teh welcome controllder
public function login() {
//restrict the acess of the login page of welcome controller
if ($this->session->userdata("user_id"))
//redirecting to the dash board page
return redirect("admin/dashboard");
//End
$this->load->view('login');
}
public function Signin() {
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');
if ($this->form_validation->run()) {
$email = $this->input->post('email');
$password = sha1($this->input->post('password'));
$this->load->model('queries');
$userExist = $this->queries->adminExist($email, $password);
echo '<pre>';
print_r($userExist);
echo '<pre>';
//information saved in the session data will be accesed when teh user loged into the system
//inside if the yser id exists user details will be stored inside the session
if ($userExist) {
if ($userExist->user_id == '1') {
$sessionData = [
'user_id' => $userExist->user_id,
'username' => $userExist->username,
'email' => $userExist->email,
'role_id' => $userExist->role_id,
];
//redirect to teh dash board upon giving teh correct user id and password
//settin user data to the dashboard
$this->session->set_userdata($sessionData);
return redirect("admin/dashboard");
//if the coadmin login session creatiion whos id is grater than 1
} else if ($userExist->user_id > '1') {
$sessionData = [
'user_id' => $userExist->user_id,
'username' => $userExist->username,
'email' => $userExist->email,
//'college_id' => $userExist->college_id,
'role_id' => $userExist->role_id,
];
//redirect to teh dash board upon giving teh correct user id and password
//settin user data to the dashboard
$this->session->set_userdata($sessionData);
return redirect("users/dashboard");
}
} else {
$this->session->set_flashdata('message', 'Email or password is incorrect');
return redirect("welcome/login");
}
} else {
$this->login();
}
}
//crerate logout function for the user to logout
public function logout() {
//closing teh session inside logout function usinhg the userid
$this->session->unset_userdata("user_id");
return redirect("welcome/login");
}
}
<?php include("inc/header.php"); ?>
<div class="container">
<h3>COADMIN DASHBOARD</h3>
<?php
// echo $username = $this->session->userdata('username');
$username = $this->session->userdata('username');
?>
<h5>Welcome <?php echo $username; ?></h5>
<hr>
<div class="row">
<table class="table table-hover">
<thead>
<th scope="col">ID</th>
<th scope="col">Student Name</th>
<th scope="col">College Name</th>
<th scope="col">Email</th>
<th scope="col">Gender</th>
<th scope="col">Course</th>
</thead>
<tbody>
<!-- if users contain the data-->
<?php //if (count($students)): ?>
<!-- Iterate the array to show he records-->
<?php //foreach ($$students as $student): ?>
<tr class="table-active">
<td><?php //echo $student->id; ?></td>
<td><?php //echo $student->studentname; ?></td>
<td><?php //echo $student->collegename; ?></td>
<td><?php //echo $student->email; ?></td>
<td><?php //echo $student->gender; ?></td>
<td><?php //echo $student->course; ?></td>
</tr>
<?php //endforeach; ?>
<?php //else: ?>
<!-- If count is 0 table will not display any data-->
<tr>
<td>No records found!</td>
</tr>
<?php //endif; ?>
</tbody>
</table>
</div>
</div>
<?php include("inc/footer.php"); ?>