Not-in-use
Not-in-use

Reputation: 79

Codeigniter - uri routing, skipping a segment

I'd like to skip a section of a uri with Code Igniter. I have the following urls

/about
/info
/admin/users
/admin/pages
/admin/pages/edit/123

However I'd like to skip admin when searching for the class, i.e. the default config acts like this:

/admin[class]/pages[function]/edit[var]/123[var]

However I'd like it to work like this:

/admin[skip]/pages[class]/edit[function]/123[var]

Unfortunately I can't just start my application one level deeper as I have top level pages too.

I'd rather not add a rule for every page if I don't have to.

Any ideas?

Thanks!

Upvotes: 3

Views: 1631

Answers (2)

permawash
permawash

Reputation: 171

@jonjdavidjohn's suggestion should work, but there is another option if you don't go that way.

In config/routes.php re-route all /admin/requests to the appropriate controller:

// if you use this structure: controllers/pages.php
$route[admin/(:any)] = '$1';

Upvotes: 2

jondavidjohn
jondavidjohn

Reputation: 62392

You can organize your controllers into subdirectories a single level deep in codeigniter out of the box.

so your directory structure would be

/application
    /controllers
        /admin
            pages.php [pages class]

Upvotes: 1

Related Questions