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

0

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

so i have to write a new route everytime when i create a function in this controller
Sir can you please clear the doubt that is that i have to create a new route everytime when i create a new function in this controller
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';

3 Comments

Thanks Your solution is working sir but can you please cleat one doubt that if i use this way so i have to create new route evertime when i create a new function?
No (:any) => $1 will relate to function whatever you created
just one last question sir can it reliable to user this way or i should continue using the old (regular) way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.