CodeIgniter Forums
HMVC and Admin - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: HMVC and Admin (/thread-49781.html)



HMVC and Admin - El Forum - 03-03-2012

[eluser]sunnyd[/eluser]
I am currently using HMVC and Phil Sturgeon's method of creating admin panel for the backend of my websites.

The problem is that sometimes the admin controller in each module can get too large and managing code much less tracking it down can be difficult.

For example, the current admin controller, let's admin_photos is used to manage photos, photo categories, tags, with each probably their own CRUD functions. Is there a way I can break this into 3 different admin controllers while still being under the Photos module.

Essentially, I am looking for something like this:

Photos
------- admin_photos.php
------- admin_tags.php
------- admin_categories.php

I would like to be able to access the backend using http://sitename.com/admin/photos/tags etc..

Is that possible?

Thanks


HMVC and Admin - El Forum - 03-03-2012

[eluser]PhilTem[/eluser]
HMVC supports routing for a module separately from the application-wide routing. As the wiki on bitbucket says

Quote:Each module may contain a config/routes.php file where routing and a default controller can be defined for that module using:
$route[‘module_name’] = ‘controller_name’;

Here's my approach from another recent project:

./application/config/routes.php
Code:
$route['admin/(:any)/(:any)'] = '$1/admin/$2';
$route['admin/(:any)'] = '$1/admin/index';

./application/modules/<module>/config/routes.php
Code:
$route['admin/photo/tags/(:any)'] = 'photo/admin_tags/$2';
$route['admin/photo/tags'] = 'photo/admin_tags/index';
$route['admin/photo/categories/(:any)'] = 'photo/admin_categories/$2';
$route['admin/photo/categories'] = 'photo/admin_categories/index';

I'm not 100% sure whether this works this way - I had the second part put directly into ./application/config/routes.php. And always remember for routes: first come first serve.


HMVC and Admin - El Forum - 03-03-2012

[eluser]sunnyd[/eluser]
Hi PhilTerm,

Thanks, for some reason. I can never get modules routes working. Up until now, I have been sticking all my routes in the main routes file. Tried the above but can seem to get it to work.

Any ideas?