0

This is my controller directery structure

controllers
-----user(folder)
----------User_reg.php //My Controller inside user folder.

-----index
-----Welcome.php

I can access User_reg.php like this:

http://localhost/coin_system/user/user_reg

Now I want to eliminate user from this URL so I added the route

$route['user_reg/(:any)'] = 'user/user_reg/$1';

But it show the error: 404 Page Not Found

I want to access it like this

http://localhost/coin_system/user_reg

How can i access the controller inside the directory in controller?

I have tried to solve using this SO question but it did't help. I am using Codeigniter latest version. 3.1.5

Community
  • 1
  • 1
always-a-learner
  • 3,671
  • 10
  • 41
  • 81

2 Answers2

2

You have missed function

https://www.codeigniter.com/user_guide/general/routing.html#examples

$route['user_reg'] = 'user/user_reg/index';
$route['user_reg/(:any)'] = 'user/user_reg/index/$1';

Or You can have different function

$route['user_reg'] = 'user/user_reg/somefunction'
$route['user_reg/(:any)'] = 'user/user_reg/somefunction/$1';

Also try with index.php in url

http://localhost/coin_system/index.php/user_reg
1

When you add route with :any it also find your calling method after controller. But for index(which is default) its not compulsory to all index method So you need to specify route for it also. So just need to add one more route

$route['user_reg'] = 'user/user_reg'; // add this to route file
$route['user_reg/(:any)'] = 'user/user_reg/$1';
B. Desai
  • 16,414
  • 5
  • 26
  • 47