always-a-learner
always-a-learner

Reputation: 3794

access controller inside the controller directory within another folder

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

Upvotes: 0

Views: 384

Answers (2)

user4419336
user4419336

Reputation:

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

Upvotes: 2

B. Desai
B. Desai

Reputation: 16436

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';

Upvotes: 1

Related Questions