Welcome Guest, Not a member yet? Register   Sign In
Should "Index" be avoided as a controller name in CodeIgniter?
#1

(This post was last modified: 07-27-2023, 03:38 AM by CharlotteFilemdar.)

Is it recommended to avoid using "Index" as the name for a controller class in CodeIgniter? I've noticed that when I have an "Index" controller, its methods are called multiple times. Specifically, the index method is always called first, regardless of whether I visit a path that should be routed there.

Here's an example from the code:


class Index extends CI_Controller
{
    public function index()
    {
        echo "index";
    }

    public function blah()
    {
        echo "blah";
    }
}
When I visit "index/blah", I see "indexblah" printed. When I visit "index/index", I see "indexindex". However, if I rename the controller to something else (e.g., "Foo"), the issue doesn't occur. While renaming the controller is a workaround, I'm curious to know why this behavior is happening. Should I report this as a bug to CodeIgniter?

(Note: I haven't set up any routes in "configs/routes.php," and my "index.php" is located developer echat outside the CodeIgniter directory.)

I appreciate any insights or advice regarding this matter.
Reply
#2

Yes index should not be used as a controller name.

Just think resevered words.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB