Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6244547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:20:43+00:00 2026-05-24T12:20:43+00:00

Should I not be using Index as the name for a controller class in

  • 0

Should I not be using Index as the name for a controller class in CodeIgniter? I have an Index controller, and I’m seeing its methods being called multiple times. More specifically, I always see its index method called first, whether or not I’m visiting a path that should be routed there.

In application/controllers/index.php

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. If I rename the controller to something else (e.g. Foo), it doesn’t have a problem. That’s the obvious workaround, but can anyone tell me why this is happening? Should I report this as a bug to CodeIgniter?

(Notes: I have no routes set up in configs/routes.php; my index.php is outside the CodeIgniter tree)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:20:44+00:00Added an answer on May 24, 2026 at 12:20 pm

    To further clarify what the issue is, in PHP4 Constructors were a function that had the same name as the Class…

    example

    class MyClass
    {
        public function MyClass()
        {
            // as a constructor, this function is called every 
            // time a new "MyClass" object is created
        }
    }
    

    Now for the PHP5 version (Which codeigniter now, as of 2.0.x, holds as a system requirement)

    class MyClass
    {
        public function __construct()
        {
            // as a constructor, this function is called every 
            // time a new "MyClass" object is created
        }
    }
    

    So To answer the question that addresses the problem…

    Should I not be using Index as the name for a controller class in CodeIgniter?

    I believe it would be best to not choose Index as a controller name as the index() function has a reserved use in codeigniter. This could cause issues depending on your PHP configuration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using TortoiseSVN against VisualSVN I delete a source file that I should not have
If we develop a winform app using an MVC architecture, it should not be
I have heard umpteen times that we 'should not mix business logic with other
I have an assembly which should not be used by any application other than
I have a WCF Service that should not enter the faulted state. If there's
When using the normal architecture (I guess it's called controller-based architecture), zend recommends the
If for example I should not use standard library functions like printf() , putchar()
The general advice is that you should not call GC.Collect from your code, but
It seems to be the general opinion that tables should not be used for
What factors indicate that a project's solution should not be coded in a dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.