Welcome Guest, Not a member yet? Register   Sign In
HMVC Routing Question
#1

[eluser]elambert[/eluser]
Hi,

My goals are to create short, friendly urls so that:
roles or roles/N paginated list with N being page number
role/N view role
add_role add new role
edit_role/N edit role N

Code:
$route['roles'] = "roles/index/";
$route['roles/(:any)'] = "roles/index/$1/";
$route['roles/(:any)/(:any)'] = "roles/index/$1/$2/";

$route['add_(:any)'] = "$1s/add/";
$route['edit_(:any)/(:num)'] = "$1s/edit/$2/";
$route['(:any)/(:num)'] = "$1s/view/$2/";

The code works, but I was hoping to find a solution were I do not have to add 2-3 specific routes for each module that I create. Is there another or better way to accomplish these goals?
#2

[eluser]ivantcholakov[/eluser]
IMO you should "standardize" all of your links, how would they look like. Then you should place common rules within the global routes.php. Thus you will not be forced to write a specific rules for similar cases. Some exceptional rules may be added later, but not too many, and they may be placed within module-specific configuration files routes.php.

Here is my global route.php form the project I work on, it is an example for an admin panel with CRUD functionality. You can see that I don't use specific segment words.

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'home';
$route['404_override'] = 'error_404';

$route['([a-zA-Z_-]+)/(:num)'] = '$1/index/$2';
$route['([a-zA-Z_-]+)/(:num)/([a-zA-Z_-]+)'] = '$1/$3/$2';
$route['([a-zA-Z_-]+)/(:num)/([a-zA-Z_-]+)/(:num)'] = '$1/$3/$2/$4';
$route['([a-zA-Z_-]+)/([a-zA-Z_-]+)/(:num)'] = '$1/$2/index/$3';
$route['([a-zA-Z_-]+)/([a-zA-Z0-9_-]+)/(:num)/([a-zA-Z_-]+)'] = '$1/$2/$4/$3';
#3

[eluser]InsiteFX[/eluser]
If your using HMVC you can have a config directory in the module name with its own routing.
#4

[eluser]elambert[/eluser]
Thank you both for your replies.

I am using a config/routes.php file for each module.




Theme © iAndrew 2016 - Forum software by © MyBB