Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 4 routes not working properly
#1
Sad 

I just got into CI4 from a CI3 background but I'm finding it difficult to get routes to display the appropriate view. Even though I have written the code in the controller properly to load a view, it always returns index.php no matter what instead of the correct view even when I enter a non-existent route. The 404 page doesn't show either. Please, what am I missing?

Here's my controller code:
Code:
<?php

namespace App\Controllers;

class Shop extends BaseController
{
    public function index()
    {
        return view('shop');
    }
}


Here's the result I get on the browser:


[Image: oHp2z.png]
Reply
#2

If you want it go to Shop then you need to create a route for it.

Did you setup your base url in app/Config/App.php
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 11-17-2020, 11:46 PM by DanielTheGeek.)

(11-17-2020, 09:43 PM)InsiteFX Wrote: If you want it go to Shop then you need to create a route for it.

Did you setup your base url in app/Config/App.php

Tried that, didn't work still. It doesn't show the 404 page for non-existent routes too.

I noticed that the mod.rewrite module was disabled all this while by running "sudo a2query -m rewrite", I don't know if this helps. I'd enable the mod.rewrite module and see what happens.

SOLVED: I simply enabled mod.rewrite by running "sudo a2enmod rewrite" and everything works as expected now.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB