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

getting $_GET variables in xenforo

Discussion in 'XenForo Development Discussions' started by z1haze, May 28, 2015.

  1. z1haze

    z1haze Member

    Hi, I am just wondering how do I go about getting the $_GET variables to pass into my callback function? I have friendly url's enabled as well. I found https://xenforo.com/community/threads/_get-in-the-url.58145/ but I dont really understand it, so if this is indeed what I need, can someone maybe help me understand this better?
     
  2. MtoR

    MtoR Well-Known Member

    Hi,

    Not sure what you are trying to achieve, but you should look into routes stuff
    Jaxel made a great tutorials on this subject.

    But as I said, this really depends of what you try to achieve.

    Clément
     
  3. z1haze

    z1haze Member

    i am building a webstats system for a game. a person can seached for other players and display the users stats.. i need to grab the search input params to return the correct user object
     
  4. MtoR

    MtoR Well-Known Member

    Then if you are doing a custom file, you need to create the adequate routes.

    Anyways, if you have a functionning route, you'd have to use the filterSingle function on the input var ($this->input->filterSingle(....) if you are in a controller) function.

    Look in xF files you'll see how it's done.

    Clément
     
  5. z1haze

    z1haze Member

    Ok I guess this is just really confusing for me. Can you help me get this setup? I can share pastes of whatever relavant code necessary just let me know what to share
     
  6. MtoR

    MtoR Well-Known Member

  7. z1haze

    z1haze Member

    I know how to create callback functions etc.. i just asked how to pass $_get variables into the functions and how that works. Directing me to 'tutorials' isnt really helping since I could have found them on my own. I was asking if ANYONE would be kind enough to help me understand how to do it rather than just doing the simple and pointing me to a tutorials section that isnt even specific.
     
  8. MtoR

    MtoR Well-Known Member

    I might not have understand your request.

    What do you call a callback function ? An action ?

    Or a callback called from templates ?
     
  9. z1haze

    z1haze Member

    I have a custom page node that is setup with a php callback that just displays a massive table of data... i want to ADD a search form to the page in which when submitted, submit the function with the $_GET variable so it will return stats for that specific player they searched for.. i mean its super simple with php ive done it a hundreds times.. example here: http://maplecraftmc.com/player.php?player_id=32 its just this xenforo crap throws me for a loop every time..
     
  10. MtoR

    MtoR Well-Known Member

    Oh ok, post your current code so that we can analyse what you might be doing wrong.

    That would help.
     
  11. z1haze

    z1haze Member

    there's nothing wrong.. the personal stats page doesnt even exist yet.. I just know there are technically 2 ways to pass php to a page right? the php callback page on the page node, and then you can call php functions within template which I have played with a bit.. I just dont know how to actually pass $_get parameters into those functions! Also, can you explain the difference of setting of your page via the php callback tab in the pagenode settings or just using a template and calling php functions with like: <xen:callback class="HomePage_Status_Callback" method="getIP"></xen:callback>
     
  12. MtoR

    MtoR Well-Known Member

    It's still unclear what you exactly try to achieve.

    If you have a custom page, then you can add the form to your code ?
    Or are you trying to do the form retrieval once posted ?
     
  13. z1haze

    z1haze Member

    lol jesus. what is unclear about 'i want to pass $_get parameters into a php function with xenforo...' that to me, is as descriptive as it gets.

    edit: Im trying to submit the form to a different page which will load a function using the damn $_GET parameters lol.. its not complicated i jsut dont know how to do it in xenforo
     
  14. MtoR

    MtoR Well-Known Member

    What is unclear is how you call that function.

    If your function is a php callback you set when creating the custom page node, you have access to all page controller variables (see XenForo_ControllerPublic_Page actionIndex()).
    PHP:
    call_user_func_array(array($page['callback_class'], $page['callback_method']), array($this, &$response));
    Then as you have access to $this (the controller), you can use the input filter to retrieve the stuff which is in your $_GET, either using filterSingle (STRING being one of the possible types for XenForo_Input) :
    PHP:
    $this->_input->filterSingle('some_variable_name'XenForo_Input::STRING);
    or the array method :
    PHP:
              $inputData $this->_input->filter(array(
                            
    "first_name"        => XenForo_Input::STRING,
                            
    "last_name"         => XenForo_Input::STRING,
                            
    "phone"             => XenForo_Input::STRING,
                            
    "address"           => XenForo_Input::STRING,
                            
    "additional_info"   => XenForo_Input::STRING
                        
    ));
     
  15. z1haze

    z1haze Member

    I dont do any of that.. This is like beyond me id say.. ill show you what i have

    PHP:
    <?php
    class Leaderboards_GlobalList_Callback
    {
        private static 
    $leaders = Array();
        private static 
    $output;
       
        private static function 
    get_GlobalList()
        {
            
    $global_list = new Leaderboards_GlobalList_Query();
            
    self::$leaders $global_list->get_GlobalList();
            unset(
    $global_list);
        }

        private static function 
    format_GlobalList()
        {
            
    self::$output "";
            if(
    is_array(self::$leaders) && count(self::$leaders) > 0)   
            {
                foreach (
    self::$leaders as $leader
                {
                    
    self::$output .= '<tr>';   
                    
    self::$output .= '<td width="150">' $leader['name'] . '</td>';
                    
    self::$output .= '<td width="70">' $leader['pvp_kills'] . '</td>';
                    
    self::$output .= '<td width="70">' $leader['pvp_deaths'] . '</td>';
                    
    self::$output .= '<td width="70">' $leader['current_streak'] . '</td>';
                    
    self::$output .= '<td width="70">' $leader['max_streak'] . '</td>';
                    
    self::$output .= '</tr>';
                }
            }
            else
            {
                
    // if some reason the query didn't work output a message to user
                
    self::$output "<li> No members found </li>";
            }
            
    self::$output '<table id="stats_table"><tr><th>Name</th><th>Kills</th><th>Deaths</th><th>Current Streak</th><th>Best Streak</th></tr>' self::$output '</table>';
        }
       
        
    /**
        * Get the Members by user groups and return the values back to the template
        * @param XenForo_ControllerPublic_Abstract $controller
        * @param XenForo_ControllerResponse_Abstract $response
        */
        
    public static function respond(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_Abstract &$response)
        {
            
    self::get_GlobalList();
            
    self::format_GlobalList();
            
    $response->templateName "test";        //name of the template to use
            
    $response->params['output'] = self::$output;        //html text to insert into the template
        
    }
    }
    ?>
     
  16. MtoR

    MtoR Well-Known Member

    So you don't use Node page PHP callback ? But callback inside templates ? (if I know get you from few posts ago)

    If so I am not sure that you have access to input stuff.
    Or perhaps by creating an instance of xF input handler, but I am not sure, that goes beyond what I know on xF.

    I would personnally have gone the Node page PHP callback way.
     
  17. z1haze

    z1haze Member

    I use the node php Callback for this page. This is the callback class that I inserted into the php node callback tab. Basically I just need to pass parameters into the creation of this class object so I can query the database for the searched player. If that makes any more sense I hope
     
  18. MtoR

    MtoR Well-Known Member

    Oh damn yes... I am stupid...

    You can get the info in the respond function.

    This should work, with some_variable_name the name of the url token you are trying to retrieve :
    PHP:
    $yourVarRetrieved $controller->_input->filterSingle('some_variable_name'XenForo_Input::STRING);
     
  19. z1haze

    z1haze Member

    I'll be home later to look into this more in not sure what this controller stuff is
     
  20. MtoR

    MtoR Well-Known Member

    Its the var in parameter of the respond function.
     

Share This Page