Welcome Guest, Not a member yet? Register   Sign In
Default Controller Parameters....
#1

[eluser]craigkoster[/eluser]
I'm developing an application with user defined subdomains (e.g. user1.domain.com, user2.domain.com) and want to be able to give a user friendly URL's to view a specific set of data. For example, if a set was called 'My Data' I'd like them to be able to go to http://user1.domain.com/my-data to see the result set instead of http://user1.domain.com/data_controller/get_data/123.

Being new to CI it seems that I'd want to be able to pass the 'my-data' part as a parameter to my default controller's default method (index()) but CI is seeing 'my-data' as the name of a controller. Through a couple searches it seems like I need to create some kind of routing but I'm not advanced enough in CI to know exactly what I need to do. If anybody has any suggestions, please let me know.

Thanks,

Craig
#2

[eluser]wabu[/eluser]
I believe there's a way to do this.

1) Don't do this Wink
2) Explicitly define all your routes
3) The last route is a catch-all: $route['(:any)'] = "default_controller/index/$1";
4) Give your default controller's default method a default parameter so people visiting the root of your app/site don't get a missing parameter error [Example: function index($dataset="") ]
5) The catch-all will catch all, so you would probably want to have some validation done in your default method (to determine whether the parameter represents a dataset name or--anything else)

I think this would work, but I also think it could cause headaches.
#3

[eluser]jedd[/eluser]
I cast my vote for wabu's first suggestion.

You've hinted that your controller is called data_controller and that this is too long and confusing for your users.

I suggest your problem might be that you don't know how to sensibly name a controller. Obviously 'data' is a bit silly, as you've just described everything a computer handles.

The second segment of your URL - the method within your controller - you've suggested might be called get_data but this suffers from the same problem, and as far as the user's concerned it's not actually getting anything, it's showing them something.

So, absent any understanding of the type of data you're intending to provide access to, perhaps just coming up with a concise and short controller name, and changing the method to something like view , might make the URL more palatable?

I guess you could change your controller name to view, and just use the index method .. but this seems a little inelegant.

How many controllers are you likely to have within your project, and how many methods within each, anyway?
#4

[eluser]craigkoster[/eluser]
Thanks for the replies. I think I will take wabu's first suggestion and avoid hacking something like that together. The controller and method names I gave were just examples and as I thought about the problem more on the way home from work I figured my default controller could just have a method named 'view' (as LT suggested) so that URL's can be http://user1.domain.com/view/my-data. Not *exactly* what I was looking for but still pretty user friendly and no kludges necessary to make it work.

Thanks again for the advice.




Theme © iAndrew 2016 - Forum software by © MyBB