1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

$_GET in the URL

Discussion in 'XenForo Development Discussions' started by viaBowl, Aug 21, 2013.

  1. viaBowl

    viaBowl Member

    Is there a built-in way to send $_GET data in the friendly URL's? I've tried a few combinations and anything extra redirects back to the homepage.

    Suggetsions?

    Thanks
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    How are you building the URLs?
     
  3. viaBowl

    viaBowl Member

    I've tried a few different combinations:

    /index.php?pages/pagename/?a=b&c=d.....

    This is in a PAGE node btw.
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    How are you trying to access them? Pages are straight HTML, you'll most likely need to be using a PHP Callback.
     
  5. viaBowl

    viaBowl Member

    my call back is ready, i just can't get past putting GET data in the URL's
     
  6. JulianD

    JulianD Well-Known Member

    You should use XenForo built in functions to build links. Any way, the link you posted above will not work. Try to change it to:

    /index.php?pages/pagename/&a=b&c=d

    And see if the data gets populated to the $_GET array.
     
  7. viaBowl

    viaBowl Member

    YES! Awesome! Thanks
     
  8. Robin De Schepper

    Robin De Schepper New Member

    JulianD, what are the proper functions to build links?
     
  9. Jeremy

    Jeremy XenForo Moderator Staff Member

    {xen:link route/action}

    There's more that you can pass to it (parameters, etc.) and it runs through the route class and will generate an appropriate link. You can find examples all over the templates of this. :)
     
  10. JulianD

    JulianD Well-Known Member

    If you have your url route on a string variable, building a link is as simple as this:

    PHP:
    XenForo_Link::buildPublicLink("account/privaty");
    Or if you'd like to use the route's built in function to build a link, the syntax is usually as follows:

    PHP:
    XenForo_Link::buildPublicLink('members'$user);
    XenForo_Link::buildPublicLink('posts'$post);
    XenForo_Link::buildPublicLink('threads'$thread);
    The first parameter is the route prefix that should be used, the second parameter is an array containing the required variables to build a link related to the route you're using. If you take a look at the thread route prefix (library/XenForo/Route/Prefix/Threads.php, there's a function called buildLink(). By calling XenForo_Link::buildPublicLink('threads', $thread), you are effectively calling the buildLink function within the Threads route.

    XenForo uses some standardized url structure that you may be already familiar with. The format is somewhat like this:

    site.com/[prefix]/[action]

    But in cases where a parameter is required, such in this thread url, where the thread_id is needed, XenForo supports another commonly used url structure:

    site.com/[prefix]/[param]/[action]

    If we take this thread url as an example, the above variables would be:

    prefix: threads
    param: _get-in-the-url.58145
    action: empty (default action, which usually means "index")

    Anyway, you can even create your own routes with very complex url structures if you ever need to, completely outside of what XenForo already uses. You just need to code the proper route functions to support your url structures :)
     

Share This Page