简体   繁体   English

找不到404页面未找到您请求的页面。笨

[英]404 Page Not Found The page you requested was not found. codeigniter

在此输入图像描述

Hi I'm quite new to codeigniter. 嗨,我对codeigniter很新。 I have a code which was working fine few days ago, but when I opened it again it is giving me the error of page you requested not found. 我有一个代码,几天前工作正常,但当我再次打开它时,它给了我你要求找不到的页面的错误。 basically the code is about adding user in database. 基本上代码是关于在数据库中添加用户。 Kindly help me here and I need you suggestions. 请帮助我,我需要你的建议。 Here is my model, controller and view codes. 这是我的模型,控制器和视图代码。

Model file 模型文件

Userinsert_model.php Userinsert_model.php

<?php
class Userinsert_model extends CI_Model{
function __construct() {
parent::__construct();
}
function form_insert($data){

$this->db->insert('students', $data);
}

public function datafetch(){
    $fetch= $this->db->get('students'); 
    return $fetch->result();

}

}



?>

Controller file 控制器文件

Userinsert_controller.php Userinsert_controller.php

<?php

class Userinsert_controller extends CI_Controller {

function __construct() {
parent::__construct();
$this->load->model('Userinsert_model');
}
function index() {

$this->load->library('form_validation');

$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

$this->form_validation->set_rules('dname', 'Username', 'required|min_length[5]|max_length[15]');

$this->form_validation->set_rules('demail', 'Email', 'required|valid_email');

$this->form_validation->set_rules('dmobile', 'Mobile No.', 'required|regex_match[/^[0-9]{10}$/]');

$this->form_validation->set_rules('daddress', 'Address', 'required|min_length[10]|max_length[50]');

if ($this->form_validation->run() == FALSE) {
$this->load->view('Userinsert_view');
} else {
$data = array(
'Student_Name' => $this->input->post('dname'),
'Student_Email' => $this->input->post('demail'),
'Student_Mobile' => $this->input->post('dmobile'),
'Student_Address' => $this->input->post('daddress')
);
$this->Userinsert_model->form_insert($data);
$data['message'] = 'Data Inserted Successfully';
$this->load->view('Userinsert_view', $data);
}
}
public function fetch() {

    $this->load->model('Userinsert_model');

        $data["all_data"]= $this->Userinsert_model->datafetch();
$this->load->helper('form');
    $this->load->view('Usershow_view', $data);  
}
}



?>

View file 查看文件

Userinsert_view.php Userinsert_view.php

<html>
<head>
<title>Insert Data Into Database Using CodeIgniter Form</title>
</head>
<body>

<div id="container">
<?php echo form_open('Userinsert_controller'); ?>

<h1>Insert Data Into Database Using CodeIgniter</h1><hr/>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br>
<?php } ?>
<?php echo form_label('Student Name :'); ?> <?php echo form_error('dname'); ?><br />
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?><br />

<?php echo form_label('Student Email :'); ?> <?php echo form_error('demail'); ?><br />
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?><br />

<?php echo form_label('Student Mobile No. :'); ?> <?php echo form_error('dmobile'); ?><br />
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile', 'placeholder' => '10 Digit Mobile No.')); ?><br />

<?php echo form_label('Student Address :'); ?> <?php echo form_error('daddress'); ?><br />
<?php echo form_input(array('id' => 'daddress', 'name' => 'daddress')); ?><br />

<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?><br/>
<div id="fugo">

</div>
</div>
</body>
</html>

In your config.php replace 在你的config.php替换

$config['index_page'] = 'index.php';  

to

$config['index_page'] = '';

重命名class Userinsert_controller extends CI_Controller {class Userinsert extends CI_Controller {然后通过example.com/index.php/userinsert访问该站点

Your application/config/routes.php must look like this 您的application/config/routes.php必须如下所示

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
|   example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
|   https://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
|   $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
|   $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
|   $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
|       my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

/* CUSTOM ROUTES */
$route['userinsert'] = 'Userinsert';

Basically you need to have the below route. 基本上你需要有以下路线。

$route['userinsert'] = 'Userinsert';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM