繁体   English   中英

CodeIgniter:“404 Page Not Found The page you request was not found”尽管设置了 routes.php

[英]CodeIgniter: "404 Page Not Found The page you requested was not found" despite setting up routes.php

我不断收到“404 Page Not Found The page you request was not found.”,尽管正确设置了 routes.php 并且还有一个 .htaccess。 我已尝试在此网站上查找此问题的解决方案,但它对我没有帮助,因为解决方案看起来像我所做的但没有任何改变,或者我无法理解人们所说的话。

路由.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'Crud';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

Crud.php

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
class Crud extends CI_Controller 
{
    public function __construct()
    {
    /*call CodeIgniter's default Constructor*/
    parent::__construct();
    
    /*load database libray manually*/
    $this->load->database();
    
    /*load Model*/
    $this->load->model('Crud_model');
    }
        /*Insert*/
    public function savedata()
    {
        /*load registration view form*/
        $this->load->view('insert');
    
        /*Check submit button */
        if($this->input->post('save'))
        {
            $data['first_name']=$this->input->post('first_name');
            $data['middle_name']=$this->input->post('middle_name');
            $data['last_name']=$this->input->post('last_name');
            $data['username']=$this->input->post('username');
            $data['password']=$this->input->post('password');
            $data['confirmpassword']=$this->input->post('confirmpassword');
            $data['birthday']=$this->input->post('birthday');
            $data['email']=$this->input->post('email');
            $data['contactnumber']=$this->input->post('contactnumber');
            $response=$this->Crud_model->saverecords($data);
            if($response==true){
                    echo "Records Saved Successfully";
            }
            else{
                    echo "Insert error !";
            }
        }
    }
    
}
?>

Crud_model.php

<?php
class Crud_model extends CI_Model 
{
    
    function saverecords($data)
    {
        $this->db->insert('TSA2exam',$data);
        return true;
    }
    
}

插入.php

<!DOCTYPE html>  
<html>
<head>
<title>Registration form</title>
</head>
 
<body>
    <form method="post" action="<?= base_url() ?>Crud/savedata">
        <table width="600" border="1" cellspacing="5" cellpadding="5">
  <tr>
    <td width="230">First Name </td>
    <td width="329"><input type="text" name="first_name"/></td>
  </tr>
  <tr>
    <td>Middle Name </td>
    <td><input type="text" name="middle_name"/></td>
  </tr>
  <tr>
    <td>Last Name </td>
    <td><input type="text" name="last_name"/></td>
  </tr>
  <tr>
    <td>Username </td>
    <td><input type="text" name="username"/></td>
  </tr>
  <tr>
    <td>Password </td>
    <td><input type="text" name="password"/></td>
  </tr>
  <tr>
    <td>Confirm Password </td>
    <td><input type="text" name="confirmpassword"/></td>
  </tr>
  <tr>
    <td>Birthday </td>
    <td><input type="text" name="birthday"/></td>
  </tr>
  <tr>
    <td>Email ID </td>
    <td><input type="email" name="email"/></td>
  </tr>
  <tr>
    <td>Contact Number </td>
    <td><input type="email" name="email"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="save" value="Save Data"/></td>
  </tr>
</table>
 
    </form>
</body>
</html>

数据库.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'tsa2',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

配置文件

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
$config['allow_get_array'] = TRUE;
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['error_views_path'] = '';
$config['cache_path'] = '';
$config['encryption_key'] = '';
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_samesite'] = 'Lax';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;
$config['cookie_samesite']  = 'Lax';
$config['standardize_newlines'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';

列出的路由与 Crud 类中的方法不匹配。 如果没有列出方法, $route['default_controller'] = 'crud'; 等同于$route['default_controller'] = 'crud/index';

因此,您要么需要在 Crud 类中创建索引方法。 function index(){

或将路线更改为:

$route['default_controller'] = 'crud/savedata';

如果 savedata 是您尝试访问的内容。

暂无
暂无

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

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