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

actionForum running twice

AndyB

Well-known member
#1
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.
 

AndyB

Well-known member
#3
Thank you, Nobita.Kun.

This works perfect.

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

    // return parent
    return parent::actionForum();
}
 

AndyB

Well-known member
#4
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.
 

Jon W

Well-known member
#6
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;
}
 

AndyB

Well-known member
#7
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;
}
 

truonglv

Formerly Nobita.Kun
#8
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.