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

Getting variable from parent

Discussion in 'XenForo Development Discussions' started by AndyB, Nov 12, 2013.

  1. AndyB

    AndyB Well-Known Member

    I extended XenForo_ControllerPublic_Search.

    How do I get the $input['keywords'] variable?

    My code:


    class Andy_SearchLog_ControllerPublic_Search extends XFCP_Andy_SearchLog_ControllerPublic_Search
        public function 
    // call parent function
    // declare variable
    $searchLogFile '';
    $searchWords '';
    // get options from Admin CP -> Options -> Convert Image -> Search Log File 
    $searchLogFile XenForo_Application::get('options')->searchLogFile;                  
            if (
    $searchLogFile != '')
    // verify log file exists
    if (file_exists($searchLogFile))
    // adjust for local timezone
    $dateline time() + XenForo_Locale::getTimeZoneOffset();
    // format date
    $formatedDate date("m/d/y h:ia"$dateline);
    // search word              
    $searchWords $input['keywords'];
    // prepare data
    $data $formatedDate ' / Search Words: ' $searchWords '
    // update log file
    $handle fopen($searchLogFile'a');
    // return parent
    return parent::actionSearch();      

    Thank you.
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    You cannot access variables from the parent.
  3. xf_phantom

    xf_phantom Well-Known Member

    just get it again

    $input = $input->_filterSingle('keywords', XenForo_Input::String)
  4. AndyB

    AndyB Well-Known Member

    Hi xf_phantom,

    When I try your suggestion:

    $searchWords $input->_filterSingle('keywords'XenForo_Input::String);
    I get the following warning:

  5. xf_phantom

    xf_phantom Well-Known Member

    Sorry, it should be $this->_input instead of $input
  6. AndyB

    AndyB Well-Known Member

    When I try:

    $searchWords $this->_input->_filterSingle('keywords'XenForo_Input::String);
    I get the following error:

  7. xf_phantom

    xf_phantom Well-Known Member

    Once again a typo:D
    $searchWords = $this->_input->filterSingle('keywords', XenForo_Input::String);:rolleyes:

    You should use an IDE, it will suggest and autocomplete the variable and method names
  8. AndyB

    AndyB Well-Known Member

    Got it!

    Here's the code that worked:

    $searchWords $this->_input->filterSingle('keywords'XenForo_Input::STRING);
    Thank you very much, xf_phanton.
  9. AndyB

    AndyB Well-Known Member

    I use Dreamweaver and it does help with variables, classes and methods. But I guess it doesn't catch every possible mistake.

Share This Page