TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
How would you handle url querys in a search? /param1/value1 or ?param1=value1
  • What is best practise?
    1. Using that pattern: /param1/value1/order_by/asc/page/10
    2. or this: ?param1=value1&order_by=asc&page=10

    Was there a method somewhere to convert the first pattern into an array? I can't find it.
  • I'd suggest 1st for "static" parameters and 2nd for dynamic parameters, for example: "products/category/subcategory?order=asc&page=10"
  • The route parameters are mainly useful when you have 1-2 parameters and they are mandatory for the action. In the case of the example you provided, the GET parameters are more useful in my opinion.
  • You should use $_GET parameters for things that change the stuff on the page. For instance, a page parameter will show you the same view, but with different results, so it should be a $_GET parameter.
  • zombor: what about route parameters? do you mean they are not intented to be used for things that change stuff on the page?
  • No, I try and stay away from that.

    _GET: To change how/what is displayed on the page
    _POST: To change things stored on the server

    I rarely have more than 3 URI segments.
  • Czukowski has good pattern.

    Use GET parameters to do something on the this one PAGE (for exemple product list)
    -sorting
    -filters
    -pagination
    -... etc

    Use ROUTE parameters to define the path to this PAGE:

    -categories
    -paths
    -id
    -... etc

    For example:

    products/rtv/radio?orderby=price?page=2

    users/5?showall=1




  • I've been going as far as even doing id's as _GET parameters: site.com/user/view.html?id=5
  • i do the same :) the id is a exception in my pattern
  • By the way, how do you create link with GET params?

    URL::site('user/view') . '?id=5';

    or

    URL::site('user/view') . URL::query(array('id' => 5)); ???



    I think both examples has issue, and there is no good solution in kohana 3.0.x now...
  • <a href="user/view.html?id=5">Hello</a>

    -_-
  • @zombor should the user save the page suddenly your links are broken if you do it like that.
  • I prefer to use GET params for anything that should not be indexed, eg: search. Using GET params for things like user/view?id=10 is bad practice, IMO. Although search engines can and will index such pages, GET params are not supposed to be included in permanent links, because GET is, by definition, non-permanent.

    Consider: products/page/1 vs products?page=1. The first URL implies that the same content will always be there, but this is highly unlikely... as products change, so will the content of the page. The second URL implies that this will always be the product list, but content may change because there is GET data associated with it. Alone, this is a not a good example, but when you start to add more content, it should be obvious: products/page/1/sort/price vs products?page=1&sort=price. This also demonstrates why using the URI for data is a bad idea, as you should be able to remove any segment from the end of a URI. With /page/1/sort/price, you can't remove a single segment, you have to remove two! The way to work around that is to use something like page:1/sort:price, but that starts to look pretty ugly. Just use GET, this is why it exists!
  • I think we need something like this to create get:

    new method URL::params :

    URL::site('user/view') . URL::params(array('id' => 5));

    or new parameter in URL::site (better soultion):

    URL::site('user/view', array('id' => 5));

    what do you think abaout it?
  • > should the user save the page suddenly your links are broken if you do it like that.

    Not if you use <base href="{{base_url}}" />

    ;)

    > Using GET params for things like user/view?id=10 is bad practice

    > The second URL implies that this will always be the product list, but content may change because there is GET data associated with it.

    This is exactly why I prefer to put ID in _GET. The *page* is the same, but the *content* differs based on the id you pass in.
  • @zombor what about variables?

    <a href='users/list' . http_build_query(array('orderby' => $orderby) ) . '>

    its backwardness :)
  • I don't understand your question.
  • @zombor

    what do you do, if you have to use variable in URL
  • <a href="user/view.html?id={{id}}">Foobar</a>

    Or, I use a reverse route in most cases, and just do <a href="{{link}}?id={{id}}">Foobar</a> in my template.
  • what if

    $id = ">alert('got you')

    You have to escape html enities!
  • Um, my templates do that automatically sir. Don't yours?
  • My views (K 3.0.7) fortunately don't do that.

    And what about encode URL? Does your templates do that too?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion