Home » Php » php – can't access the controller function(s) in code igniter

php – can't access the controller function(s) in code igniter

Posted by: admin July 12, 2020 Leave a comment

Questions:

hi my folder sturcture is like this

controllers/user/registration/register.php

Inside the register.php controller there is let say for test index function saying ‘hello world’.But i cant access the folder index through browser.

My base_url is

$config['base_url'] = 'http://localhost/new/';

But while i write

localhost/new/index.php/user/registration/register/index

I got an error

The page you requested was not found. 

what is weird is, I can access the controller fxn of user folder but cant access the controller fxn inside registration folder .And for default controller i have ‘home.php’

$route['default_controller'] = "home";
$route['404_override'] = '';

I just want to access the controller/user/registration/register/index fxn which says ‘hello world’ but it says an error-‘The page you requested was not found’.
Thanks

How to&Answers:

Codeigniter only supports a single level directory structure for Controllers.

Try this link below for Multi Level Subfolder Controller in CodeIgniter :

Multi Level Subfolder Controller in CodeIgniter

Answer:

Ok after writing some hunch code in my test project ,finally it worked in my case
So here it goes
I follow this link Multi Level Subfolder Controller in CodeIgniter(thanks to K u s h)

http://glennpratama.wordpress.com/2009/10/20/multi-level-subfolder-for-controller-in-codeigniter/

and copy the code and paste in my new/application/core/MY_Router.php as told in that link
and an error came to me like this

Call to undefined method CI_Router::CI_Router() in C:\xampp\htdocs\new\application\core\MY_Router.php

So i changed a little portion of that code to

//  Function MY_Router()
//  {
//      parent::CI_Router();
//  }
   public function __construct()
   {
        parent::__construct();
        // Your own constructor code
   }

And after i was able to access the controllers/user/registration/register.php index fxn

It worked in my case.Thanks to all