Search code examples
codeignitercontrollerroutessubcontroller

Code Igniter doesn't recognize my function in controller under a folder


I have a folder under my main controller-folder called admin, in that controller i have a file name admin.php which has a function xyz.

I want to access that function using this url

http://localhost/webroot/admin/xyz

However when I try to access it, it is giving me this error.

404 Page Not Found

The page you requested was not found.

this is code of my routes.php file

$default_controller = "welcome";
$controller_exceptions = array('welcome','forum');
$route['default_controller'] = $default_controller;
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = '';
$route['admin'] = "admin/admin";

This is my .htaccess file

 RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]  

Also mod-rewrite is enabled :)

Please let me know why is it not working and how can i make it work. Any kind of help is really appreciated. Thanks


Solution

  • Ensure that your routes are stored in application/config/routes.php (not router.php as specified in your question). Try adding a route that uses a wildcard, like this:

    $route['admin']        = "admin/admin";    //Routes to 'index()' function
    $route['admin/(:any)'] = "admin/admin/$1"; //Handles all other cases
    

    :any will match a segment containing any character(s), after the admin segment, and will pass it/remmap it to the the admin controller.

    The user guide contains more information on controllers in sub-folders and routing.