Welcome Guest, Not a member yet? Register   Sign In
maintaining the default controller's URL location
#1

[eluser]Kyle Ellman[/eluser]
So, I know with a default controller, you can have
Code:
example.com/
instead of
Code:
example.com/index.php/deafault_controller

but if there is anything else in the URL like using one of that controller's functions, I get an error, so instead of being able to use
Code:
example.com/function
I am forced to use
Code:
example.com/index.php/default_controller/function

I know this may create problems if a function has the same name as another controller, but is there anyway to do this if I know that there's won't be any URL conflicts in my application?


Thanks.
#2

[eluser]Michael Wales[/eluser]
Custom URI Routing
#3

[eluser]Kyle Ellman[/eluser]
I had spent some time looking at that but I don't completely understand how to use it with my situation.

I have four controllers: application, admin, show, and folder. admin uses show and folder, so the user really only sees either application and admin. admin needs to be at .com/admin and application must remain at .com/

application will take url arguments and has no functions, so I'm using the _remap function instead. so, how would I go about using the custom URI routing to maintain, say, .com/something/somethingelse rather than .com/application/something/somethingelse?

Thanks.
#4

[eluser]Michael Wales[/eluser]
Code:
$route['something/somethingelse'] = 'application/something/somethingelse';
#5

[eluser]Kyle Ellman[/eluser]
Well, the something and the somethingelse will be names generated by the user stored in a database. There's no telling what it may be.
#6

[eluser]Michael Wales[/eluser]
You can use Regex in the routes, so you define all of your routes that you know, then implement a catch-all route that will pass the value in the URL to a controller method that will then determine where to go.
Code:
$route['admin'] = 'admin';
$route['show'] = 'show';
$route['([a-z]+)'] = 'users/view/$1';

Code:
function show($username) {
  echo $username;
}
#7

[eluser]Kyle Ellman[/eluser]
doing this messed up the rest of the application (the whole thing not just the application controller)

I'm not sure what to do at this point.

To be very specific, this application needs to run in a subdirectory if placed there as well.
These are the actual URLs that need to exist:

Code:
/admin
/admin/options
/admin/login

/show/create/[a number]
/show/edit/[a number]
/show/delete/[a number]

/folder/create/[a number]
/folder/edit/[a number]
/folder/delete/[a number]

anything else would be used by the 'application' controller with could be
Code:
/anything/somethingelse/anythingelse
because the URL segments are what the user will think are folders that are generated by the user.

also there will most likely be an install script actually located at /install.php


Thanks for any and all help.
#8

[eluser]Kyle Ellman[/eluser]
Alright, so, I fixed it. After playing around with it a bit, I found that (when placed under the default and scaffolding routs, of course) this worked perfectly.

Code:
$route['admin'] = 'admin';
$route['admin/([a-z]+)'] = 'admin/$1';

$route['show'] = 'show';
$route['show/([a-z]+)'] = 'show/$1';
$route['show/([a-z]+)/(\d+)']  = 'show/$1/$2';

$route['folder'] = 'folder';
$route['folder/([a-z]+)'] = 'folder/$1';
$route['folder/([a-z]+)/(\d+)']  = 'folder/$1/$2';

$route[':any'] = 'application';

Thanks for the recommendation on the regular expressions.




Theme © iAndrew 2016 - Forum software by © MyBB