Getting variable from parent

AndyB

Well-known member
I extended XenForo_ControllerPublic_Search.

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

My code:

PHP:
<?php

class Andy_SearchLog_ControllerPublic_Search extends XFCP_Andy_SearchLog_ControllerPublic_Search
{  
    public function actionSearch()
    {
        // call parent function
        parent::actionSearch();
      
        // 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');
                fwrite($handle, $data);
                fclose($handle);
            }
        }
        // return parent
        return parent::actionSearch();      
    }
}

?>

Thank you.
 
Hi xf_phantom,

When I try your suggestion:

PHP:
$searchWords = $input->_filterSingle('keywords', XenForo_Input::String);

I get the following warning:

Warning: Uncaught exception 'ErrorException' with message 'Undefined variable: input' in
...
Fatal error: Call to a member function _filterSingle() on a non-object in
 
When I try:

PHP:
$searchWords = $this->_input->_filterSingle('keywords', XenForo_Input::String);

I get the following error:

Fatal error: Call to undefined method XenForo_Input::_filterSingle() in /home/southbay/www/forums/library/Andy/SearchLog/ControllerPublic/Search.php on line 28
 
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
 
Got it!

Here's the code that worked:

PHP:
$searchWords = $this->_input->filterSingle('keywords', XenForo_Input::STRING);

Thank you very much, xf_phanton.
 
Top Bottom