Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 371
Not-in-use Avatar asked May 01 '26 04:05

Not-in-use


2 Answers

@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';
like image 129
permawash Avatar answered May 03 '26 18:05

permawash


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]
like image 43
jondavidjohn Avatar answered May 03 '26 19:05

jondavidjohn