eg my URLs and their resulting actions , will be like:
1) a: For a user whose company_id belongs to company = Pepsi
/pepsi/ - controller - users, action - dashboard (their Auth->user 'company_id' will be used and their user->id)
/pepsi/companies/view - controller - companies, action - view
/pepsi/users/ - controller - users, action - index (trailing slash preferably optional)
/pepsi/users/dashboard - controller - users, action - dashboard
1) b: For a user who company_id belongs to company = Coke
/coke/ - controller - users, action - dashboard
/coke/companies/view - controller - companies, action - view
/coke/users/ - controller - users, action - index (trailing slash preferably optional)
/coke/users/dashboard - controller - users, action - dashboard
2) For an admin, which uses routing prefix adminperson
/adminperson/users - controller - users, action - index
/adminperson/users/view/3 - controller - users, action - view , id = 3
/adminperson/companies/delete/6 - controller - companies, action - delete Id = 6
3) important Then also when a user isnt logged in , there are ALSO public pages.
/contents/view/3 – controller – contents, action – view AND id = 3
Below is the best I have got so far, but it always demands the action index to be explicitly written to the URL – but in fact I guess its not that bad a problem as the Html->link helper should produce it. I am happy to build all my links with the helper as I usually do that.
best try :
Router::connect('/:companyslug/:controller/:action', array('controller' => 'companies', 'action'=>'index', 'companyslug'=>'test'));
I have a similar setup, except I’m keeping track of the first part of the route to determine what records are displayed. Here’s my setup, where “:app” is in place of what you call “:companyslug”:
Note: this is from Cake 2.0RC3, but I believe it should work the same in 1.3.
This way you can retrieve the value of app in the controller (under request parameters) and make sure they are in the correct URL (make sure company_id = companyslug in your case).
One tricky bit is the ‘persist’ option, which means you always need to use the Html Helper’s link function to maintain the correct prefix in the URL.