codeigniter-4

CodeIgniter 4.6.0 Loads Default Page Only


I'm starting a new project and below is my setup on Windows 11. Everything is a fresh install.

Now, I run "php spark serve" from the command line and then load localhost:8080 from my browser. The default page Home.php loads up and appears to be working. But when I try localhost:8080/home, I get a 404 error. Then, I create Home2.php as a test. I still get a 404 error when I open localhost:8080/home2.

I try changing $uriProtocol in app/Config/App.php from REQUEST_URI to QUERY_STRING. The problem now is that if I open home2 or home or even non-existent pages, it still loads the default page (e.g., localhost:8080/awraseasfs still loads default page). So, then I try changing $uriProtocol to PATH_INFO and it's the same issue as using REQUEST_URI.

So far, below is what I have tried/checked:

What else am I missing? I don't remember this being an issue in CI2 and CI3. Any help is very much appreciated. Thank you!

UPDATE: I pointed the doc root to myproject/public instead of using php spark serve. The issue is still the same. The default page is the only thing that loads. What I noticed tho is that when I load localhost/index.php, the php code is displayed in plain text. So, what is going on?!? I can't even follow the tutorials just to test things out.


Solution

  • Thank you for your interest in CodeIgniter.

    1. I recommend that you study the documentation in full. It will take about an hour.

    2. Windows is not fully supported, but everything should work.

    3. To add a route, you need to edit the file app/Config/Routes.php . For the new route /home, you need to insert the code:

    $routes->get('/home', 'Home::index');
    // or
    $routes->get('/home2', 'Home2::index');
    

    4. If you don't want to write each route yourself, you can use Auto Routing Improve.

    5. When running spark, you are using only the PHP server. Because of this, you will need to configure VirtualHost later. So far, Apache is not required for development.