![]() |
[solved] Tricky Folder Layout - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [solved] Tricky Folder Layout (/showthread.php?tid=14759) |
[solved] Tricky Folder Layout - El Forum - 01-14-2009 [eluser]helmutbjorg[/eluser] Hi Guys, Really starting to get into codeigniter now. One more thing before i'm fully sold. Say i want to have the following folders on my website Code: example.com/account Each of those relates to a controller Code: controllers/account.php Each controller has several functions for example Code: example.com/account/delete But I cannot do this. The name conflict with the account controller interferes with having the orders and images controllers accessed from what is essentially a subfolder. Even if i try the following code in routes.php config Code: $route['account/orders'] = 'account_orders'; I haven't explained it very well but do you guys get what i mean? [solved] Tricky Folder Layout - El Forum - 01-14-2009 [eluser]xwero[/eluser] The file structure doesn't need to reflect the url structure. If you have not a lot of code you can put everything in one controller. If you have a lot of code you can create a directory and add controllers to it. For routing as you expect you have to put the specific route above the general route. [solved] Tricky Folder Layout - El Forum - 01-14-2009 [eluser]helmutbjorg[/eluser] So what you're saying is this? I want the following folders in the url Code: example.com/account Each of those relates to a controller Code: controllers/account_index.php By using the following routes? Code: $route['account'] = 'account_index'; Is that correct? [solved] Tricky Folder Layout - El Forum - 01-14-2009 [eluser]xwero[/eluser] Lets say you have not a lot of code and you put all the things in one controller Code: class Accounts extends Controller Code: $route['account/(delete|other|actions)(.*)'] = 'account/index/$1$2'; If you want to split the controllers to have smaller files you could go for following file structure actions/actions.php : the index function in the controller above actions/orders.php actions/images.php And in the routing this will have following result Code: $route['account'] = 'account/account'; [solved] Tricky Folder Layout - El Forum - 01-14-2009 [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 Each of those relates to a controller Code: controllers/account.php Each controller has several functions for example Code: example.com/account/delete Adding the following code into routes.php config Code: $route['account/orders/(:any)'] = 'account_orders/$1'; 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 And you add the following to the top of routes.php config file Code: $route['account/orders/archive/(:any)'] = 'account_orders_archive/$1'; 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! [solved] Tricky Folder Layout - El Forum - 01-14-2009 [eluser]Phil Sturgeon[/eluser] You can reduce your rotues a little there to make them easier to maintain and save you adding a new one for each controller you add. Code: $route['account/(:any)/archive/(:any)'] = 'account_$1_archive/$2'; |