Pierce McGeough
Pierce McGeough

Reputation: 3086

Use routes for mulitlevel folders in CodeIgniter

Is it possible to use CodeIgniter to route to sub folders. My current folder setup is like this with my routes line to access my owners controller. The url i am access is www.site.com/owners/home

controllers /
        login.php
        owners /
                home.php
                profile.php
        students /
                home.php
                profile.php

$route['owners'] = "owners/home";

I would like to put the owners and students into a seperate folder, to group them, but access them through the same url and not show the users folder. I was hoping the route below would get me where I wanted.

controllers /
        login.php
        users / 
                owners /
                        home.php
                        profile.php
                students /
                        home.php
                        profile.php

$route['users/owners'] = "owners/home";

Upvotes: 1

Views: 38

Answers (1)

GrahamTheDev
GrahamTheDev

Reputation: 24825

$route['owners'] = "users/owners";    
$route['owners/(:any)'] = "users/owners/$1";     

You got it back to front the part to the left is the bit in the URL -> the part to the right is the part that defines where the path will go in the controllers.

The second statement might be necessary to ensure controllers methods still work - depends on your routes.php file as my customised install is now heavily modified!

Upvotes: 1

Related Questions