Welcome Guest, Not a member yet? Register   Sign In
Help creating a route for sub-folder holding controllers
#1

(This post was last modified: 10-07-2015, 11:31 AM by jLinux.)

In my CI application, all of the administrative actions are in controllers within the /controllers/admin/ folder....

Quote:[root@server application]# tree controllers/
controllers/
|-- Account.php
|-- Api.php
|-- Assets.php
|-- Dashboard.php
|-- Group.php
|-- Help.php
|-- Main.php
|-- Page.php
|-- Partition.php
|-- REST
| |-- Account.php
| |-- Admin.php
| |-- Analytics.php
| |-- App.php
| |-- Assets.php
| |-- Key.php
| |-- Page.php
| `-- Partition.php
|-- admin
| |-- Accounts.php
| |-- Backups.php
| |-- Groups.php
| |-- Home.php
| |-- Logs.php
| |-- Pages.php
| |-- Partitions.php
| |-- Plugins.php
| |-- Recyclebin.php
| |-- Roles.php
| |-- Settings.php
| `-- Support.php
`-- index.html

The question I had was how can I have it so when they go to application.com/admin/, it shows a resource in a specified controller?

I tried adding the following to application/config/routes.php, but it didn't work:
PHP Code:
$route['admin'] = '/admin/home'
I tried it with/without the slash after admin, as well as with/without slashes before/after the admin/home didn't work.

Obviously creating an Admin.php inside the application/controllers/ directory would work for the /admin/ index, but make all the controllers inside the application/controllers/admin/ inaccessible.

Thanks!
Reply
#2

I think narf mentioned the default route has to be top level and there are no plans to change this.

The way I get around this is to set the route to go to a controller at the top level.

Then in that controller I do a redirect...

E.g

redirect("admin/home", "refresh");

Not sure if that is what you mean?
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

(10-07-2015, 01:53 PM)iamthwee Wrote: I think narf mentioned the default route has to be top level and there are no plans to change this.

The way I get around this is to set the route to go to a controller at the top level.

Then in that controller I do a redirect...

E.g

redirect("admin/home", "refresh");

Not sure if that is what you mean?

You mean put an Admin.php controller in the /application/controllers/ directory, and put a redirect in the Admin::index resource? That would kill all the other controllers in the /application/controllers/admin/ directory
Reply
#4

which version of codeigniter are you using? if you are using codeigniter 2 then use this, it allows you to use subfolders in the controller 

https://degreesofzero.com/article/contro...niter.html

you just create the file, drop it in, and thats it, works perfectly. 
if its CI 3, or if above solution does not work for CI 2, try adding index to the route
$route['admin'] = '/admin/home/index'; 
Reply
#5

(10-07-2015, 04:56 PM)cartalot Wrote: which version of codeigniter are you using? if you are using codeigniter 2 then use this, it allows you to use subfolders in the controller 

https://degreesofzero.com/article/contro...niter.html

you just create the file, drop it in, and thats it, works perfectly. 
if its CI 3, or if above solution does not work for CI 2, try adding index to the route
$route['admin'] = '/admin/home/index'; 

Im using CI3

And $route['admin'] = '/admin/home/index';  seemed to work! Wow, I guess it was because I didn't specify the index resource, assumed it would go to it automatically... Guess thats what happens when I assume >.<


Thanks!
Reply
#6

Quote:And $route['admin'] = '/admin/home/index';  seemed to work! Wow, I guess it was because I didn't specify the index resource, assumed it would go to it automatically... Guess thats what happens when I assume >.<

glad it helped!  

yeah there seem to be cases with CI 3 where you need to have 'index' in the route, but i haven't dived into it to figure out which conditions it is -- if anyone knows?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB