Welcome Guest, Not a member yet? Register   Sign In
Building Really Long URIs - Function Specific or Controller Specific or ???
#1

[eluser]Jondolar[/eluser]
What are some best practices for building URLs? Do you have each segment specifically defined based on the function that will be called or based on the controller that is being called or based on something else?

For example of a category page:
domain.com/category/category/123/456
controller = category
function = category
3rd segment = categoryid
4th segment = not used or used for something not related to a specific productid

For example of a product page:
domain.com/category/product/123/456
controller = category
function = product
3rd segment = categoryid
4th segment = productid

It seems that each controller/function would have a very specific layout for it's own URI. Is that the right approach? I'm sure an answer could be "it depends" or "you can do it any way you want" but I'd like to hear some specifics around why/when this would be good or why/when it would not be good. This will help me define the best approach for my projects.

Thanks in advance.
#2

[eluser]Colin Williams[/eluser]
I would say, in RESTful terms, you generally do /resource/verb/guid/key/value/key/value... and so on. With proper REST, you would drop the /verb/ part and rely on request methods, but since browsers only do GET and POST, well... not much choice. Also, you can consider swapping verb/guid, guid/verb, but you'll need to use _remap to do that correctly.

Also, you might have sub-resources with related resources, like /project/1255/user/445/tasks, which would be an index of all tasks assigned to user 455 for project 1255. The prototype of this uri is /resource/guid/resource/guid/resource/verb (verb is implied "GET index"). As far as CI is concerned, this would be the Project controller, and possibly the index() function or something specific like task_index() or user_task_index(). There is flexibility here too. Maybe your URI is /project/1255/task/user/445. However you want, really.
#3

[eluser]Jondolar[/eluser]
This is great information. I didn't consider the key/value/key/value as a way to look at it. I will be able to consider that as I map out my URL plans.

Anybody have any other "best practices" approaches?

Thanks.
#4

[eluser]Colin Williams[/eluser]
Quote:I didn’t consider the key/value/key/value as a way to look at it

This is how you abandon the query string. Surprisingly, most people don't get it right away (count the amount of "How do I use $_GET and segments?" threads per day).




Theme © iAndrew 2016 - Forum software by © MyBB