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

No controller response error message

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

  1. AndyB

    AndyB Well-Known Member

    I'm getting the following error message in my Server Error Logs:

    XenForo_Exception: No controller response from Andy_SimilarThreads_ControllerPublic_Abstract::actionIndex - library/XenForo/FrontController.php:455

    In my Similar Threads add-on I have an option to show similar threads when a new thread is being created. If this feature is disabled (un-checked) the code bypasses the main part of the function. Here's a link to the code:

    http://xenforo.com/community/threads/similar-threads-v1-4.62374/#post-661591

    In this situation I can't just add the following code:

    PHP:
    //option not set return parent action
    return parent::actionIndex();
    because there's no actionIndex() parent in the default ControllerPublic_Abstract file.

    What is the correct code to avoid the error message?

    Thank you.
     
  2. AndyB

    AndyB Well-Known Member

    I was able to resolve this problem by changing the code so that it always runs. The template just returns nothing when the option is disabled.
     
  3. Jeremy

    Jeremy XenForo Moderator Staff Member

    This is why you are supposed to extend pre-defined controllers unless you are defining a new section of the website.
     
  4. AndyB

    AndyB Well-Known Member

    Thank you for looking at this, Jeremy.

    I extended XenForo_ControllerPublic_Forum instead of XenForo_ControllerPublic_Abstract but it didn't solve the problem. I still get an error message in my server error logs if I try to bypass my code (option deselected).

    If I add the following code after bypassing my main code:

    PHP:
    } else {
    // run the original save() function
    return parent::actionIndex();
    the AJAX routine will display the forum list in place of where the similar threads results would normally be shown.
     
    Last edited: Nov 4, 2013
  5. AndyB

    AndyB Well-Known Member

    Here's the code as I have it now:

    PHP:
    <?php

    class Andy_SimilarThreads_ControllerPublic_Forum extends XFCP_XenForo_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: Nov 4, 2013
  6. AndyB

    AndyB Well-Known Member

    Si if the $showCreateThread == 1 I bypass my code. All is fine but I get the following error messages in the server error log:

     
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

  8. AndyB

    AndyB Well-Known Member

  9. Jeremy

    Jeremy XenForo Moderator Staff Member

    It breaks your AJAX how?
     
  10. AndyB

    AndyB Well-Known Member

    As soon as I start typing into the thread title input box, I get an error message. This is the error message:

     
  11. Jeremy

    Jeremy XenForo Moderator Staff Member

    Did you properly extend it using listeners? Plenty of people have used it with AJAX.
     
  12. AndyB

    AndyB Well-Known Member

    Yes I created a Code Event Listener and added the proper code to Listener.php file.
     
  13. AndyB

    AndyB Well-Known Member

    Listener.php

    PHP:
    <?php

    class Andy_SimilarThreads_Listener
    {
        public static function 
    Thread($class, array &$extend)
        {
            
    $extend[] = 'Andy_SimilarThreads_ControllerPublic_Thread';
        }    
        
        public static function 
    Forum($class, array &$extend)
        {
            
    $extend[] = 'Andy_SimilarThreads_ControllerPublic_Forum';
        }    
    }

    ?>
     
  14. AndyB

    AndyB Well-Known Member

    The Code Event Listener:

    pic001.jpg
     
  15. Jeremy

    Jeremy XenForo Moderator Staff Member

    And you are properly hitting the forums/ route in your AJAX call?
     
  16. Daniel Hood

    Daniel Hood Well-Known Member

    You started the file with
    PHP:
    class Andy_SimilarThreads_ControllerPublic_Forum extends XFCP_Andy_SimilarThreads_ControllerPublic_Forum
    right?
     
  17. Chris D

    Chris D XenForo Developer Staff Member

    You said there was an error when you tried it. What was the error?
     
  18. AndyB

    AndyB Well-Known Member

    Hi Daniel,

    That's correct.

    Sorry I did a copy paste. When I was doing my test I indeed had XFCP in the class.
     
  19. AndyB

    AndyB Well-Known Member

    Hi Chris,

    Post #10 of this thread shows the exact error message.
     
  20. Chris D

    Chris D XenForo Developer Staff Member

    Ah sorry. I missed the error at first.

    If you have any other add-ons where you've not used the class proxy system, this could be an expected behaviour.
     

Share This Page