Welcome Guest, Not a member yet? Register   Sign In
[solved] Tricky Folder Layout
#5

[eluser]helmutbjorg[/eluser]
Thanks heaps xwero! So going kinda from what you have said I have come up with a working solution.

Say i want to have the following folders on my website
Code:
example.com/account
example.com/account/orders
example.com/account/images

Each of those relates to a controller
Code:
controllers/account.php
controllers/account_orders.php
controllers/account_images.php

Each controller has several functions for example
Code:
example.com/account/delete
example.com/account/orders/view
example.com/account/orders/delete
example.com/account/images/upload

Adding the following code into routes.php config
Code:
$route['account/orders/(:any)'] = 'account_orders/$1';
$route['account/orders'] = 'account_orders';
$route['account/images/(:any)'] = 'account_images/$1';
$route['account/images'] = 'account_images';

Which works great!

Now if we want to take this method further. Say you want to put another controller underneath the orders folder like so:
Code:
example.com/account/orders/archive/

Then that would map to the following controller
Code:
controllers/account_orders_archive.php

And that controller can now have its own functions
Code:
example.com/account/orders/archive/download
example.com/account/orders/archive/generate
example.com/account/orders/archive/delete

And you add the following to the top of routes.php config file
Code:
$route['account/orders/archive/(:any)'] = 'account_orders_archive/$1';
$route['account/orders/archive'] = 'account_orders_archive';
$route['account/orders/(:any)'] = 'account_orders/$1';
$route['account/orders'] = 'account_orders';
$route['account/images/(:any)'] = 'account_images/$1';
$route['account/images'] = 'account_images';
Note how the rule must be above the subfolder it is contained within. So that there are no conflicts. The higher rule takes priority. That was the key!

Thanks for your help. I like this solution as it keeps the controllers folder organised. If anybody has any better solutions for me let me know!


Messages In This Thread
[solved] Tricky Folder Layout - by El Forum - 01-14-2009, 04:52 AM
[solved] Tricky Folder Layout - by El Forum - 01-14-2009, 05:03 AM
[solved] Tricky Folder Layout - by El Forum - 01-14-2009, 05:17 AM
[solved] Tricky Folder Layout - by El Forum - 01-14-2009, 05:33 AM
[solved] Tricky Folder Layout - by El Forum - 01-14-2009, 06:15 AM
[solved] Tricky Folder Layout - by El Forum - 01-14-2009, 06:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB