No controller response error message

In post #5 the first line you can see I have not extended the XFCP properly. Once I fixed that I have successfully extended XenForo_ControllerPublic_Forum using XFCP.

However there's a problem, as soon as I go to create a thread and type into the thread title area, I get the following error.

An exception occurred: Cannot load class using XFCP. Load the class using the correct loader first. in /home/southbay/www/forums/library/XenForo/Autoloader.php on line 108

Apparently the AJAX code and/or Route Prefix are not working with the XFCP system.

Here's my code.

PHP:
<?php

class Andy_SimilarThreads_ControllerPublic_Forum extends XFCP_Andy_SimilarThreads_ControllerPublic_Forum
{
    public function actionIndex()
    {
        // call parent function
        parent::actionIndex();
   
        // declare variables
        $currentNodeId = '';
        $currentThreadId = '';
        $similarThreads = array();
        $searchWords = array();
        $searchWord1 = '';
        $searchWord2 = '';       
        $safeSearchWord1 = '';
        $safeSearchWord2 = '';
   
        // get options from Admin CP -> Options -> Similar Threads -> Show Create Thread
        $showCreateThread = XenForo_Application::get('options')->showCreateThread;
   
        if ($showCreateThread == 1)
        {
            // get newTitle
            $newTitle = $this->_request->getParam('title');

            // put into array
            $newTitle = explode(' ', $newTitle);
       
            // get options from Admin CP -> Options -> Similar Threads -> Common Words
            $commonWords = XenForo_Application::get('options')->commonWords;
       
            // convert to lowercase
            $commonWords = strtolower($commonWords);
       
            // put $commonWordsLower into an array
            $commonWords = explode(' ', $commonWords);
       
            // remove any common words from array
            foreach($newTitle as $var)
            {
                if (!in_array(strtolower($var), $commonWords))
                {
                    // get options from Admin CP -> Options -> Similar Threads -> Miniumum Common Word Length
                    $minimumCommonWordLength = XenForo_Application::get('options')->minimumCommonWordLength;               
               
                    if (strlen($var) >= $minimumCommonWordLength)
                    {
                        $searchWords[] = $var;
                    }
                }
            }
       
            $count = count($searchWords);
       
            // only continue if we have a search word
            if ($count > 0)
            {           
                // get first search word
                $searchWord1 = $searchWords[0];
           
                // make safe for query
                $safeSearchWord1 = addslashes($searchWords[0]);
           
                if ($count > 1)
                {
                    // get second search word
                    $searchWord2 = $searchWords[1];
                       
                    // make safe for query
                    $safeSearchWord2 = addslashes($searchWords[1]);
                }       
            }
       
            // run query only if we have a search and option is selected
            if ($safeSearchWord1 != '' AND $showCreateThread == 1)
            {
                // run query in model
                $similarThreads = $this->getModelFromCache('Andy_SimilarThreads_Model')->getThreads($safeSearchWord1,$safeSearchWord2,$currentNodeId,$currentThreadId);
            }
       
            // prepare $viewParams for template
            $viewParams = array(
                'similarThreads' => $similarThreads,
                'searchWord1' => $searchWord1,
                'searchWord2' => $searchWord2,
            );
       
            // send to template
            return $this->responseView('Andy_SimilarThreads_ViewPublic_SimilarThreads', 'andy_similarthreads_create_thread', $viewParams);
        }
    }
}

?>
 
Last edited:
Also, if you are doing an AJAX call there is no need to return anything but your own data, you are wasting bandwidth if you are.
 
Then you shouldn't be extending action.Index, you are then wasting CPU time by running code to never return its values.
 
Then you shouldn't be extending action.Index, you are then wasting CPU time by running code to never return its values.

Oh that makes sense. I'll try giving it a unique name and see if I can get it to work that way.

Thank you.
 
So I changed the function to "public function showCreateThread()", but I get the same error message.

pic001.webp
 
It needs to be actionName

Thank you, Jeremy. So I named it actionIndex2 [public function actionIndex2()] and changed my Route Prefix file accordingly. I still get the same error message.

As soon as I start typing into the thread title input I get the error message.

Here's my Route Prefix file:

PHP:
<?php

class Andy_SimilarThreads_Route_Prefix_SimilarThreads implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        return $router->getRouteMatch('Andy_SimilarThreads_ControllerPublic_Forum', 'Index2', $routePath);
    }
}

?>
 
You need to decide if you are either:

1) Extending an existing controller using the class proxy system

or

2) Creating a new controller which is accessed via a newly created route prefix

Right now you're doing half of each and it's not working.
 
Here's my .js file

Code:
!function($, window, document, _undefined)
{
	XenForo.similarthreadsId = function($form)
	{		
		var typewatch = (function()
		{
			var timer = 0;
			return function(callback, ms)
			{
				clearTimeout (timer);
				timer = setTimeout(callback, ms);
			}  
		})(); 
		$title = $form.find('input[name="title"]');
		$title.keyup(function() 
		{
			typewatch(function () 
			{
				XenForo.ajax(
				$('base').attr('href') + 'similarthreads/',
				$form.serializeArray(),
				function(ajaxData, textStatus)
				{
					if (ajaxData.templateHtml)
					{
						new XenForo.ExtLoader(ajaxData, function()
						{
							$('#similarthreadsId-result').html('<div>' + ajaxData.templateHtml + '</div>');
						});
					}
				});
			}, 500);
		});		
	}	
	XenForo.register('#similarthreadsId', 'XenForo.similarthreadsId');	
}
(jQuery, this, document);
 
You are extending an existing route. You do not use your route and instead use the forums route as I described earlier.
 
You need to decide if you are either:

1) Extending an existing controller using the class proxy system

or

2) Creating a new controller which is accessed via a newly created route prefix

Right now you're doing half of each and it's not working.

Hi Chris,

Thank you for taking your time to review this situation.

I'm not sure what I need to do. Here's what I understand.

1) I would like using AJAX to show similar threads when a user starts to type into the thread title input form
2) I was extending XenForo_ControllerPublic_Abstract w/o XFCP
3) Everything works great, but could not bypass the code if the option is unchecked
4) Running the code but returning an empty template worked, but seamed like bad coding
5) I was told to extend another controller, so I chose XenForo_ControllerPublic_Forum
6) I was also told I should always use XFCP
7) I was told I don't need a Route Prefix
8) I removed the Route Prefix and now the AJAX doesn't work at all
 
Top Bottom