actionForum running twice

AndyB

Well-known member
Hello,

In my add-on Forum Views:

https://xenforo.com/community/resources/forum-views.4089/

I'm counting how many times the forum_list is displayed. This currently works great as I'm extending the the actionIndex like this:

PHP:
<?php

class Andy_ForumViews_ControllerPublic_Forum extends XFCP_Andy_ForumViews_ControllerPublic_Forum
{	
	public function actionIndex()
	{	
		// get parent		
		$parent = parent::actionIndex();	

<code removed for brevity>

		// return parent
		return $parent;
	}

Now I would like to also count how many times the forum_view is displayed, so I'm extending the actionForum like this:

PHP:
public function actionForum()
	{
		// get parent		
		$parent = parent::actionForum();	

<code removed for brevity>

		// return parent
		return $parent;
	}

The problem I'm seeing is each time the forum_view is displayed, the actionForum appears to run twice. What am I missing?

Thank you.
 
Thank you, Nobita.Kun.

This works perfect.

PHP:
public function actionForum()
{
    <code removed for brevity>

    // return parent
    return parent::actionForum();
}
 
Unfortunately further testing shows the solution in post #3 is not working.

What I have noticed is the problem only occurs when the forum has more than one page. So for example if the forum has 5 total threads, the actionForum() runs once, but if the forum has 500 threads, the actionForum() runs twice.
 
Do you just need to check that it is not counting redirects?

PHP:
public function actionForum()
{
    $response = parent::actionForum();

    if ($response instanceof XenForo_ControllerResponse_View) {
     <code removed for brevity>
    }

    return $response;
}
 
Hi Jon W,

Thank you for taking the time to look at this issue, unfortunately checking for XenForo_ControllerResponse_View didn't work. I found the solution by adding the following code.

PHP:
// return parent action if response is not viewing first page
if ($parent->params['page'] != 1)
{
    return $parent;
}
 
Hi Jon W,

Thank you for taking the time to look at this issue, unfortunately checking for XenForo_ControllerResponse_View didn't work. I found the solution by adding the following code.

PHP:
// return parent action if response is not viewing first page
if ($parent->params['page'] != 1)
{
    return $parent;
}

If sometime the parent not responseView. You will get an error. You should ensure that it return as view and do it.
 
Back
Top Bottom