PostMans
PostMans

Reputation: 338

CodeIgniter HMVC routes

Currently working on a CodeIgniter application using HMVC

The HMVC app has his own routing.php containing

$route['finance/bill/add'] = 'finance/show_addBill';

$route['finance/transaction/add'] = 'finance/show_addTransaction';

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

$route['finance'] = 'finance';

the application has an Finance controller. When going to

http://localhost/finance** it goes to **public function index(){}

http://localhost/finance/transaction/add DOES NOT go to **public function show_addTransaction() {}

http://localhost/finance/addTransaction DOES goes to **public function show_addTransaction() {}

I can not figure out why above routes aren't working :S

Upvotes: 0

Views: 2415

Answers (1)

GrahamTheDev
GrahamTheDev

Reputation: 24815

You shouldn't be defining routes in an HMVC application (as a very strong rule of thumb - there are exceptions but it is rare).

You should have a folder structure like:

Modules
- Finance
- - Controllers
- - - finance //should have index, add and an other generic functions.
- - - transaction // transactions specific functions
- - - bill // bill specific functions.

The routing is automatic - along these lines:

url/finance -> look for Modules/Finance/Controllers/Finance/Index()

url/finance/bill -> it will look for Modules/Finance/Controllers/Finance(.php)/Bill() FIRST then Modules/Finance/Controllers/Bill(.php)/index()

So for your scenario you should have:

$route['finance/bill/add']

A bill.php controller - with class bill - with a method add

$route['finance/transaction/add']

A transaction.php controller - with class transaction - with a method add

$route['finance/(:any)']

Doesn't exist - as I said the URL routing is automatic so provided you have the relevant controllers and methods things will be found

$route['finance']

Simple finance.php controller with index method.

Upvotes: 1

Related Questions