You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Codeigniter问题求助:URL未找到+登录后无法跳转至book.php视图

Hey there, let's work through your CodeIgniter issues one by one—this framework has a few gotchas when you're starting out, but we'll get everything working smoothly.

1. Fixing "The requested URL was not found on this server" for localhost/reservation/

This error usually boils down to URL routing or server configuration missteps. Here's what to check step by step:

  • Verify your base URL setting
    Open application/config/config.php and make sure base_url points to your project's root. If your CodeIgniter project lives in a folder named reservation, it should look like:

    $config['base_url'] = 'http://localhost/reservation/';
    
  • Enable Apache's rewrite module
    If you're using XAMPP/WAMP, open your Apache httpd.conf file and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (remove the # at the start). Restart Apache after this change—this is required to remove index.php from your URLs.

  • Check your .htaccess file
    Make sure your project root has an .htaccess file with the standard CodeIgniter rewrite rules:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    This tells Apache to route all requests through CodeIgniter's index.php without showing it in the URL.

  • Confirm your controller exists
    You need a controller named Reservation.php (capitalized first letter) in application/controllers/ with an index() method that loads your login view. Example:

    class Reservation extends CI_Controller {
        public function index() {
            // Load the login view when accessing localhost/reservation/
            $this->load->view('login');
        }
    }
    
2. Fixing Login Form Redirection to the book.php View

Your current form has no action attribute, so it submits to the same page without triggering the right controller logic. Here's how to fix it:

  • Update your form's action attribute
    Modify your form to point to a dedicated controller method that handles login and loads the book view. Use CodeIgniter's base_url() helper to avoid hardcoding URLs:

    <form class="" method="POST" action="<?php echo base_url('reservation/login'); ?>">
        <div>
            <button class="btn btn-primary" name="login">Login</button>
        </div>
    </form>
    
  • Add the login method to your Reservation controller
    In Reservation.php, add a login() method to process the form submission and load the book view. You can add credential validation logic here later, but for now, this will handle the redirect:

    public function login() {
        // Optional: Add login validation logic here (e.g., check username/password)
        
        // Load the book view after login
        $this->load->view('book');
    }
    
  • Enable the URL helper
    To use base_url(), you need to load the URL helper. You can autoload it in application/config/autoload.php:

    $autoload['helper'] = array('url');
    

    Or load it dynamically in your controller's constructor:

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
    }
    
  • Double-check your view files
    Make sure login.php and book.php are both located in application/views/—CodeIgniter won't find them if they're in the wrong folder or named incorrectly.

Give these steps a shot, and if you run into any specific snags (like new error messages or missing files), feel free to share more details!

内容的提问来源于stack exchange,提问作者Emjey23

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:22:01